buildrs tested and refactored

This commit is contained in:
Wiktor Mazur
2019-12-16 12:04:55 +01:00
parent d20223ecc8
commit 3e9b648c2e
4 changed files with 42 additions and 6 deletions
+11 -6
View File
@@ -1,15 +1,13 @@
// build.rs
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("itemdb.rs");
let mut f = File::create(&dest_path).unwrap();
save_file("itemdb.rs", &generate_itemdb());
}
fn generate_itemdb() -> String {
let mut out = String::new();
out.push_str("use std::collections::HashMap;\n");
@@ -28,5 +26,12 @@ fn main() {
out.push_str("};\n");
out.push_str("}");
f.write_all(out.as_bytes()).unwrap();
out
}
fn save_file(file_name: &str, content: &str) {
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join(file_name);
let mut f = File::create(&dest_path).unwrap();
f.write_all(content.as_bytes()).unwrap();
}