forked from steveklabnik/rust-by-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.rs
47 lines (36 loc) · 1.04 KB
/
update.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
#![deny(warnings)]
#![feature(phase)]
extern crate regex;
#[phase(plugin)]
extern crate regex_macros;
extern crate serialize;
use example::Example;
mod example;
mod file;
mod markdown;
mod playpen;
fn main() {
let examples = Example::get_list();
let (tx, rx) = channel();
let mut nexamples = 0;
for (i, example) in examples.into_iter().enumerate() {
let tx = tx.clone();
let count = example.count();
spawn(proc() {
example.process(vec!(i + 1), tx, 0, String::new());
});
nexamples += count;
}
let mut entries = range(0, nexamples).map(|_| {
rx.recv()
}).collect::<Vec<(Vec<uint>, 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.as_slice()) {
Err(why) => panic!("{}", why),
Ok(_) => {},
}
}