1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
use std::path::PathBuf;
use crate::{config::Filters, project::Project, Config};
use self::entry::SearchPath;
pub mod entry;
type EntryIter = std::vec::IntoIter<PathBuf>;
#[derive(Debug, Default, Clone)]
pub struct Search {
pub paths: Vec<PathBuf>,
pub add: Vec<PathBuf>,
pub filters: Filters,
}
impl Search {
pub fn new(
Config {
paths,
add,
filters,
verbosity: _,
}: Config,
) -> Self {
Self {
paths,
add,
filters,
}
}
}
impl IntoIterator for Search {
type Item = Project;
type IntoIter = SearchIter;
fn into_iter(self) -> Self::IntoIter {
SearchIter {
iter: self.paths.into_iter(),
config: self.filters,
curr: None,
}
}
}
#[derive(Debug)]
pub struct SearchIter {
iter: EntryIter,
config: Filters,
curr: Option<SearchPath>,
}
impl Iterator for SearchIter {
type Item = Project;
#[tracing::instrument]
fn next(&mut self) -> Option<Self::Item> {
match self.curr.as_mut().and_then(|c| c.next()) {
Some(proj) => Some(proj),
None => {
self.curr = Some(SearchPath::new(self.iter.next()?, &self.config));
self.next()
}
}
}
}
|