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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use crate::WalkItem;
use std::{
ffi::{OsStr, OsString},
path::{Path, PathBuf},
};
pub mod sync_iter;
#[cfg(feature = "tokio")]
pub mod tokio_iter;
pub struct WalkPlan {
pub check_list: Vec<PathBuf>,
pub follow_symlinks: bool,
pub depth_first: bool,
pub threads: usize,
pub reject_when: fn(&Path, usize) -> bool,
pub ignore_when: fn(OsString) -> bool,
pub finish_when: fn(&WalkItem) -> bool,
}
impl Default for WalkPlan {
fn default() -> Self {
Self {
check_list: vec![],
follow_symlinks: false,
depth_first: false,
threads: 8,
reject_when: |_, _| false,
ignore_when: |_| false,
finish_when: |_| false,
}
}
}
impl WalkPlan {
pub fn new<P: AsRef<Path>>(path: P) -> Self {
Self { check_list: vec![path.as_ref().to_path_buf()], ..Default::default() }
}
pub fn roots<I>(roots: I) -> Self
where
I: IntoIterator,
I::Item: AsRef<Path>,
{
Self { check_list: roots.into_iter().map(|p| p.as_ref().to_path_buf()).collect(), ..Default::default() }
}
pub fn breadth_first_search(mut self) -> Self {
self.depth_first = false;
self
}
pub fn depth_first_search(mut self) -> Self {
self.depth_first = true;
self
}
pub fn with_threads(mut self, threads: usize) -> Self {
self.threads = threads;
self
}
pub fn reject_if(mut self, f: fn(&Path, usize) -> bool) -> Self {
self.reject_when = f;
self
}
pub fn ignore_if(mut self, f: fn(OsString) -> bool) -> Self {
self.ignore_when = f;
self
}
pub fn finish_if(mut self, f: fn(&WalkItem) -> bool) -> Self {
self.finish_when = f;
self
}
}