use walkdir::WalkDir; struct Args { targets: Vec<&'static str>, } fn is_ruby_source(path: &std::path::Path) -> bool { if let Some(ext) = path.extension() { return ext == "rb"; } false } fn main() { let args = Args { targets: vec!["."], }; let (work_send, work_recv) = crossbeam::channel::unbounded(); // produce a thread which populates the channel with work let producer = std::thread::spawn(move || { for target in args.targets { for entry in WalkDir::new(target).into_iter().filter_map(|e| e.ok()) { if is_ruby_source(entry.path()) { work_send.send(entry).expect("Unable to send work from producer thread"); } } } }); // produce a set of threads which let workers: Vec> = (0..8).map(|id| { let receiver = work_recv.clone(); std::thread::spawn(move || { while let Ok(msg) = receiver.recv() { println!("thread {} processing {:?}", id, msg); } println!("thread {} done", id); }) }).collect(); producer.join().unwrap(); for w in workers { w.join().unwrap(); } }