blob: 6b302934691956e4c3295df2fb54ae8d27a2aa20 (
plain)
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
|
use self::entry::SearchEntry;
use crate::{config::SearchEntryConfig, project::ProjectItem};
pub mod entry;
type EntryIter = std::vec::IntoIter<SearchEntryConfig>;
pub struct Search {
iter: EntryIter,
curr: Option<SearchEntry>,
}
impl std::fmt::Debug for Search {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Projects")
.field("paths_iter", &self.iter)
.finish_non_exhaustive()
}
}
impl<T> From<T> for Search
where
T: IntoIterator<IntoIter = EntryIter>,
{
fn from(value: T) -> Self {
Self {
iter: value.into_iter(),
curr: None,
}
}
}
impl Iterator for Search {
type Item = ProjectItem;
#[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(self.iter.next()?.into());
self.next()
}
}
}
}
|