Skip to content

Commit

Permalink
feat(modules): wrap iterator in its own type
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Mar 1, 2023
1 parent f8792ad commit ee99bee
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions crates/node-maintainer/src/maintainer.rs
Expand Up @@ -24,6 +24,20 @@ use crate::{Graph, IntoKdl, Lockfile, LockfileNode, Node};

const DEFAULT_CONCURRENCY: usize = 50;

#[derive(Debug)]
pub struct ModuleIterator<I>(I);

impl<I> Iterator for ModuleIterator<I>
where
I: Iterator<Item = ModuleInfo>,
{
type Item = ModuleInfo;

fn next(&mut self) -> Option<Self::Item> {
self.0.next()
}
}

#[derive(Debug, Clone)]
pub struct ModuleInfo {
pub package: Package,
Expand Down Expand Up @@ -216,8 +230,8 @@ impl NodeMaintainer {
self.graph.inner.node_count() - 1
}

pub fn iter_modules(&self) -> impl Iterator<Item = ModuleInfo> + '_ {
self.graph
pub fn iter_modules(&self) -> ModuleIterator<impl Iterator<Item = ModuleInfo> + '_> {
ModuleIterator(self.graph
.inner
.node_indices()
.filter(|idx| idx != &self.graph.root)
Expand All @@ -235,7 +249,7 @@ impl NodeMaintainer {
package: node.package.clone(),
module_path,
}
})
}))
}

#[cfg(not(target_arch = "wasm32"))]
Expand Down

0 comments on commit ee99bee

Please sign in to comment.