difi/
lib.rs

1use std::fs::{read_to_string, File};
2use std::io::Write;
3use std::path::Path;
4
5const DIF_STATIC: &'static str = "#[no_mangle]\npub static DIF_FILE: &'static [(&'static str, &'static str)] = &";
6
7/// Creates a Rust file called ``dif.rs`` which has the DIF turned into a Rust static which can be
8/// turned into a [``Dif``](https://docs.rs/dif/latest/dif/struct.Dif.html) value.
9pub fn add_dif(dif_path: &str) {
10    let dif = File::open(dif_path);
11    let rust_dif = File::create("src/dif.rs"); // Should be included in lib.rs for device driver
12
13    if dif.is_err() {
14        panic!("Failed to open DIF file ({})", dif_path);
15    } else if rust_dif.is_err() {
16        panic!("Failed to create Rust DIF file (src/dif.rs)");
17    }
18
19    rust_dif.unwrap().write_fmt(format_args!("{}{}{}", DIF_STATIC, read_to_string(Path::new(dif_path)).unwrap(), ";\n"));
20}