adjective-adjective-animal/build.rs
Fletcher Nichol d9dc0eafbf Inline the word data with a build script.
This gets me back to exactly what I was hoping for: 2 plaintext files
that would be "inlined" into native code which could be statically
built. The build script was the key here. Happy now ;)

Signed-off-by: Fletcher Nichol <fnichol@nichol.ca>
2016-04-29 19:07:14 -06:00

25 lines
806 B
Rust

use std::env;
use std::fs::File;
use std::io::{BufReader, BufWriter};
use std::io::prelude::*;
use std::path::Path;
fn main() {
generate(Path::new("data").join("adjectives.txt").as_path(),
Path::new(&env::var("OUT_DIR").unwrap()).join("adjectives.rs").as_path());
generate(Path::new("data").join("nouns.txt").as_path(),
Path::new(&env::var("OUT_DIR").unwrap()).join("nouns.rs").as_path());
}
fn generate(src_path: &Path, dst_path: &Path) {
let src = File::open(src_path).unwrap();
let src = BufReader::new(src);
let dst = File::create(dst_path).unwrap();
let mut dst = BufWriter::new(dst);
write!(dst, "[\n").unwrap();
for word in src.lines() {
write!(dst, "\"{}\",\n", &word.unwrap()).unwrap();
}
write!(dst, "];\n").unwrap();
}