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
use crate::WalkItem;
use std::{
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 finish_when: fn(&WalkItem) -> bool,
}
impl WalkPlan {
pub fn new<P: AsRef<Path>>(path: P) -> Self {
Self {
check_list: vec![path.as_ref().to_path_buf()],
follow_symlinks: false,
depth_first: false,
threads: 8,
reject_when: |_, _| false,
finish_when: |_| false,
}
}
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 stop_if(mut self, f: fn(&WalkItem) -> bool) -> Self {
self.finish_when = f;
self
}
}