-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.rs
31 lines (27 loc) · 848 Bytes
/
build.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
use std::{
env,
fs::File,
io::{self, BufRead, BufReader, BufWriter, Write},
path::Path,
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let out_dir = env::var("OUT_DIR")?;
println!("{}", &out_dir);
let out_dir = Path::new(&out_dir);
let src_dir = Path::new("data");
generate(
src_dir.join("adjectives.txt"),
out_dir.join("adjectives.rs"),
)?;
generate(src_dir.join("nouns.txt"), out_dir.join("nouns.rs"))?;
Ok(())
}
fn generate(src_path: impl AsRef<Path>, dst_path: impl AsRef<Path>) -> io::Result<()> {
let src = BufReader::new(File::open(src_path.as_ref())?);
let mut dst = BufWriter::new(File::create(dst_path.as_ref())?);
writeln!(dst, "[")?;
for word in src.lines() {
writeln!(dst, "\"{}\",", &word.unwrap())?;
}
writeln!(dst, "]")
}