summaryrefslogtreecommitdiffstats
path: root/src/projects.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/projects.rs')
-rw-r--r--src/projects.rs51
1 files changed, 27 insertions, 24 deletions
diff --git a/src/projects.rs b/src/projects.rs
index 70ea891..23530a7 100644
--- a/src/projects.rs
+++ b/src/projects.rs
@@ -1,6 +1,6 @@
use crate::{Config, Result};
use figment::Provider;
-use ignore::{Walk, WalkBuilder};
+use ignore::Walk;
use std::{path::PathBuf, vec::IntoIter};
use tracing::warn;
@@ -9,8 +9,16 @@ pub use entry::SearchPath;
mod entry;
pub struct Projects {
- paths_iter: IntoIter<SearchPath>,
- iter: Option<Walk>,
+ search_path_iter: IntoIter<SearchPath>,
+ walk: Option<Walk>,
+}
+
+impl std::fmt::Debug for Projects {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("Projects")
+ .field("paths_iter", &self.search_path_iter)
+ .finish_non_exhaustive()
+ }
}
impl Projects {
@@ -29,8 +37,8 @@ impl Projects {
impl From<Vec<SearchPath>> for Projects {
fn from(value: Vec<SearchPath>) -> Self {
Self {
- paths_iter: value.into_iter(),
- iter: None,
+ search_path_iter: value.into_iter(),
+ walk: None,
}
}
}
@@ -44,23 +52,18 @@ impl From<Config> for Projects {
impl Iterator for Projects {
type Item = PathBuf;
- #[tracing::instrument(skip(self))]
+ #[tracing::instrument]
fn next(&mut self) -> Option<Self::Item> {
- loop {
- match self.iter.as_mut().and_then(|iter| iter.next()) {
- Some(Ok(d)) => return Some(d.into_path()),
- Some(Err(err)) => warn!("{:?}", err),
- None => {
- let next = self.paths_iter.next()?;
- self.iter = Some(
- WalkBuilder::new(next.path)
- .standard_filters(true)
- .max_depth(next.recurse)
- .hidden(next.hidden)
- .build(),
- );
- }
- };
+ if self.walk.is_none() {
+ self.walk = Some(self.search_path_iter.next()?.into());
+ };
+
+ match self.walk.as_mut()?.next()? {
+ Ok(d) => Some(d.into_path()),
+ Err(err) => {
+ warn!("{:?}", err);
+ None
+ }
}
}
}
@@ -89,17 +92,17 @@ mod tests {
SearchPath {
path: project_dir.to_owned(),
hidden: false,
- recurse: Some(1),
+ max_depth: Some(1),
},
SearchPath {
path: project3.to_owned(),
hidden: false,
- recurse: Some(0),
+ max_depth: Some(0),
},
SearchPath {
path: project4.to_owned(),
hidden: false,
- recurse: Some(0),
+ max_depth: Some(0),
},
]));