use std::{fs, path::PathBuf, str};
const REPLACE_PRIMITIVES: (&str, &str, &str, &str) = ("u128", "Bitmap128", "128", "bitmap128");
const WITH_PRIMITIVES: [(&str, &str, &str, &str); 5] = [
("u64", "64", "64", "bitmap64"),
("u32", "32", "32", "bitmap32"),
("u16", "16", "16", "bitmap16"),
("u8", "8", "8", "bitmap8"),
("usize", "Arch", "usize", "bitmap_arch"),
];
fn create_or_replace(
src_dir_path: String,
replace: (&str, &str, &str, &str),
with: Vec<(&str, &str, &str, &str)>,
) {
let original = fs::read_to_string(String::from(&src_dir_path) + replace.3 + ".rs").unwrap();
for write_values in with {
let path: PathBuf = [".", &src_dir_path, &(String::from(write_values.3) + ".rs")]
.iter()
.collect();
let path = path.as_path();
let mut new_content = String::from(&original).replace(replace.0, write_values.0);
new_content = new_content.replace(replace.1, &(String::from("Bitmap") + write_values.1));
new_content = new_content.replace(replace.2, write_values.2);
match fs::write(path, new_content) {
Ok(_) => {}
Err(error) => {
eprintln!("Could not write to file!");
eprintln!("File path: {}", path.to_str().unwrap());
eprintln!("Caused by: {}", error);
}
}
}
}
fn create_or_replace_tests() {
create_or_replace(
String::from("./tests/primitives/"),
REPLACE_PRIMITIVES,
Vec::from(WITH_PRIMITIVES),
);
}
fn create_or_replace_modules() {
create_or_replace(
String::from("./src/primitives/"),
REPLACE_PRIMITIVES,
Vec::from(WITH_PRIMITIVES),
);
}
fn main() {
create_or_replace_tests();
create_or_replace_modules();
}