forked from rust-lang/rust-by-example
-
Notifications
You must be signed in to change notification settings - Fork 28
/
main.rs
64 lines (50 loc) · 1.52 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
52
53
54
55
56
57
58
59
60
61
62
63
64
#![feature(os)]
#![feature(io)]
#![feature(std_misc)]
#![feature(path)]
#![feature(core)]
#![deny(warnings)]
#![feature(int_uint)]
#![feature(plugin)]
extern crate regex;
extern crate "rustc-serialize" as rustc_serialize;
use std::os;
use example::Example;
use std::thread::Thread;
use std::sync::mpsc;
mod example;
mod file;
mod markdown;
mod playpen;
fn main() {
let args = os::args();
let mut postfix = String::new();
if args.len() > 1 && !args[1].as_slice().is_empty() {
postfix.push('_');
postfix.push_str(args[1].as_slice()); // language code such as "zh-CN"
}
let examples = Example::get_list(postfix.as_slice());
let (tx, rx) = mpsc::channel();
let mut nexamples = 0;
for (i, example) in examples.into_iter().enumerate() {
let tx = tx.clone();
let count = example.count();
let postfix = postfix.clone();
let _ = Thread::scoped(move || {
example.process(vec!(i + 1), tx, 0, String::new(), postfix);
});
nexamples += count;
}
let mut entries = range(0, nexamples).map(|_| {
rx.recv().unwrap()
}).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(_) => {},
}
}