2019-01-22 17:01:33 -05:00
|
|
|
use std::env;
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::{BufWriter, Write};
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
pub const CORPUS: &[u8] = include_bytes!("./assets/words.csv");
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("codegen.rs");
|
|
|
|
let mut file = BufWriter::new(File::create(&path).unwrap());
|
|
|
|
|
|
|
|
println!("rerun-if-changed=./assets/words.csv");
|
2019-04-17 09:30:17 -04:00
|
|
|
write!(&mut file, "use unicase::UniCase;").unwrap();
|
|
|
|
write!(
|
|
|
|
&mut file,
|
2019-06-14 16:53:34 -04:00
|
|
|
"pub(crate) static DICTIONARY: phf::Map<unicase::UniCase<&'static str>, &'static str> = "
|
2019-04-17 09:30:17 -04:00
|
|
|
)
|
|
|
|
.unwrap();
|
2019-01-22 17:01:33 -05:00
|
|
|
let mut builder = phf_codegen::Map::new();
|
2019-04-17 09:30:17 -04:00
|
|
|
let records: Vec<_> = csv::Reader::from_reader(CORPUS)
|
|
|
|
.records()
|
|
|
|
.map(|r| r.unwrap())
|
|
|
|
.collect();
|
2019-01-22 17:01:33 -05:00
|
|
|
for record in &records {
|
|
|
|
let value = format!(r#""{}""#, &record[1]);
|
2019-04-17 09:30:17 -04:00
|
|
|
builder.entry(unicase::UniCase(&record[0]), &value);
|
2019-06-14 17:19:15 -04:00
|
|
|
#[cfg(features = "iterate_unstable")]
|
2019-06-14 17:14:42 -04:00
|
|
|
break;
|
2019-01-22 17:01:33 -05:00
|
|
|
}
|
2019-04-17 09:30:17 -04:00
|
|
|
builder.build(&mut file).unwrap();
|
2019-01-22 17:01:33 -05:00
|
|
|
write!(&mut file, ";\n").unwrap();
|
|
|
|
}
|