pub struct WalkParallel { /* private fields */ }Expand description
WalkParallel is a parallel recursive directory iterator over files paths in one or more directories.
Only file and directory paths matching the rules are returned. By default,
ignore files like .gitignore are respected. The precise matching rules
and precedence is explained in the documentation for WalkBuilder.
Unlike Walk, this uses multiple threads for traversing a directory.
Implementations§
Source§impl WalkParallel
impl WalkParallel
Sourcepub fn run<F>(self, mkf: F)
pub fn run<F>(self, mkf: F)
Execute the parallel recursive directory iterator. mkf is called
for each thread used for iteration. The function produced by mkf
is then in turn called for each visited file path.
Examples found in repository?
examples/walk.rs (lines 35-43)
13fn main() {
14 let mut path = env::args().nth(1).unwrap();
15 let mut parallel = false;
16 let mut simple = false;
17 let (tx, rx) = channel::bounded::<DirEntry>(100);
18 if path == "parallel" {
19 path = env::args().nth(2).unwrap();
20 parallel = true;
21 } else if path == "walkdir" {
22 path = env::args().nth(2).unwrap();
23 simple = true;
24 }
25
26 let stdout_thread = thread::spawn(move || {
27 let mut stdout = io::BufWriter::new(io::stdout());
28 for dent in rx {
29 write_path(&mut stdout, dent.path());
30 }
31 });
32
33 if parallel {
34 let walker = WalkBuilder::new(path).threads(6).build_parallel();
35 walker.run(|| {
36 let tx = tx.clone();
37 Box::new(move |result| {
38 use ignore::WalkState::*;
39
40 tx.send(DirEntry::Y(result.unwrap())).unwrap();
41 Continue
42 })
43 });
44 } else if simple {
45 let walker = WalkDir::new(path);
46 for result in walker {
47 tx.send(DirEntry::X(result.unwrap())).unwrap();
48 }
49 } else {
50 let walker = WalkBuilder::new(path).build();
51 for result in walker {
52 tx.send(DirEntry::Y(result.unwrap())).unwrap();
53 }
54 }
55 drop(tx);
56 stdout_thread.join().unwrap();
57}Auto Trait Implementations§
impl Freeze for WalkParallel
impl !RefUnwindSafe for WalkParallel
impl Send for WalkParallel
impl Sync for WalkParallel
impl Unpin for WalkParallel
impl !UnwindSafe for WalkParallel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more