summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-10-02 13:09:45 +0300
committerLars Wirzenius <liw@liw.fi>2018-10-02 13:09:45 +0300
commite1148bfa643f2eb63a5e35df9ce95c5469a2a160 (patch)
tree1b485477e857bdfb9c5b63f807fafd8a84f64d44 /src
parent8481c6d0c0ba49743a6a7cba0ec0e731f430aed1 (diff)
downloadsummainrs-e1148bfa643f2eb63a5e35df9ce95c5469a2a160.tar.gz
Change: use the rayon crate for concurrency
Diffstat (limited to 'src')
-rw-r--r--src/main.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index e797b58..d49266b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,21 +2,30 @@ extern crate chrono;
extern crate crypto_hash;
extern crate serde_yaml;
extern crate walkdir;
+extern crate rayon;
use std::env;
use std::io;
use std::collections::BTreeMap;
use walkdir::{WalkDir, DirEntry};
+use rayon::prelude::*;
mod format;
+type Map = BTreeMap<&'static str, String>;
+
+
fn main() -> io::Result<()> {
for dirname in env::args().skip(1) {
- let maps = WalkDir::new(&dirname)
+ let maps: Vec<DirEntry> = WalkDir::new(&dirname)
.into_iter()
.filter_map(|e| e.ok())
- .map(|e| mkmap(e));
+ .collect();
+ let maps: Vec<Map> = maps
+ .into_par_iter()
+ .map(mkmap)
+ .collect();
for map in maps {
println!("{}", serde_yaml::to_string(&map).unwrap());
}
@@ -25,7 +34,7 @@ fn main() -> io::Result<()> {
}
-fn mkmap(e: DirEntry) -> BTreeMap<&'static str, String> {
+fn mkmap(e: DirEntry) -> Map {
let fields = vec![
("Name", format::name(&e)),
("Mtime", format::mtime(&e)),