forked from rust-lang/rust-by-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
51 lines (39 loc) · 1.17 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#![deny(warnings)]
#![allow(deprecated)]
extern crate regex;
extern crate rustc_serialize;
use example::Example;
use std::thread;
use std::sync::mpsc;
use std::path::Path;
mod example;
mod file;
mod markdown;
mod playpen;
fn main() {
let examples = Example::get_list();
let (tx, rx) = mpsc::channel();
let mut children = vec![];
let mut nexamples = 0;
for (i, example) in examples.into_iter().enumerate() {
let tx = tx.clone();
let count = example.count();
children.push(thread::spawn(move || {
example.process(vec!(i + 1), tx, 0, String::new());
}));
nexamples += count;
}
for child in children { let _ = child.join(); }
let mut entries = (0..nexamples).map(|_| {
rx.recv().unwrap()
}).collect::<Vec<(Vec<usize>, String)>>();
entries.sort_by(|&(ref i, _), &(ref j, _)| i.cmp(j));
let summary = entries.into_iter()
.map(|(_, s)| s)
.collect::<Vec<String>>()
.connect("\n");
match file::write(&Path::new("stage/SUMMARY.md"), &summary) {
Err(why) => panic!("{}", why),
Ok(_) => {},
}
}