extern crate crypto_hash; extern crate crossbeam_channel; use std::io::BufReader; use crypto_hash::{Algorithm, hex_digest}; use crossbeam_channel as channel; use std::thread; use std::io::prelude::*; use std::fs::File; const NWORKERS: usize = 10; pub fn rainbow(file: &str) { let f = File::open(file).unwrap(); let reader = BufReader::new(f); let (sx, rx) = channel::unbounded(); let prod = thread::spawn(move|| { for line in reader.lines() { let _ = sx.send(line.unwrap()); } }); let mut workers = Vec::with_capacity(NWORKERS); for _ in 0..NWORKERS { let rx = rx.clone(); workers.push(thread::spawn(move|| { loop { match rx.try_recv() { Some(line) => { let _digest = hex_digest(Algorithm::MD5, line.as_bytes()); // println!("{}", _digest); }, None => break } } })); } let _ = prod.join(); for _ in 0..NWORKERS { workers.pop().unwrap().join().unwrap(); } }