fast_walker/dir_walker/
mod.rs1use crate::{WalkError, WalkItem};
2use std::{
3 collections::VecDeque,
4 path::{Path, PathBuf},
5};
6pub mod rev_iter;
7pub mod sync_iter;
8#[cfg(feature = "tokio")]
9pub mod tokio_iter;
10
11#[derive(Clone)]
13pub struct WalkPlan {
14 pub check_list: Vec<PathBuf>,
16 pub follow_symlinks: bool,
18 pub depth_first: bool,
20 pub capacity: usize,
22 pub threads: usize,
24 pub reject_when: fn(&WalkItem) -> bool,
26 pub ignore_when: fn(&WalkItem) -> bool,
28 pub finish_when: fn(&WalkItem) -> bool,
30}
31
32impl Default for WalkPlan {
33 fn default() -> Self {
34 Self {
35 check_list: vec![],
36 follow_symlinks: false,
37 depth_first: false,
38 capacity: 256,
39 threads: 8,
40 reject_when: |_| false,
41 ignore_when: |_| false,
42 finish_when: |_| false,
43 }
44 }
45}
46
47impl WalkPlan {
48 pub fn new<P: AsRef<Path>>(path: P) -> Self {
50 Self { check_list: vec![path.as_ref().to_path_buf()], ..Default::default() }
51 }
52 pub fn roots<I>(roots: I) -> Self
54 where
55 I: IntoIterator,
56 I::Item: AsRef<Path>,
57 {
58 Self { check_list: roots.into_iter().map(|p| p.as_ref().to_path_buf()).collect(), ..Default::default() }
59 }
60 pub fn breadth_first_search(mut self) -> Self {
62 self.depth_first = false;
63 self
64 }
65 pub fn depth_first_search(mut self) -> Self {
67 self.depth_first = true;
68 self
69 }
70 pub fn with_threads(mut self, threads: usize) -> Self {
72 self.threads = threads;
73 self
74 }
75 pub fn reject_if(mut self, f: fn(&WalkItem) -> bool) -> Self {
86 self.reject_when = f;
87 self
88 }
89 pub fn ignore_if(mut self, f: fn(&WalkItem) -> bool) -> Self {
102 self.ignore_when = f;
103 self
104 }
105 pub fn finish_if(mut self, f: fn(&WalkItem) -> bool) -> Self {
106 self.finish_when = f;
107 self
108 }
109}