protocol

Function protocol 

Source
pub fn protocol<P: AsRef<Path>>(path: P) -> Result<TokenStream>
Examples found in repository?
examples/build.rs (line 37)
30fn wl_codegen(protocol: &str) {
31    let spec = &format!("protocol/{}.toml", protocol.to_kebab_case());
32    let proto = &format!("{PROTO_DIR}/{protocol}.rs");
33
34    println!("cargo:rerun-if-changed={spec}");
35    println!("cargo:rerun-if-changed={proto}");
36
37    let code = match yutani_codegen::protocol(spec) {
38        Ok(code) => code,
39        Err(error) => panic!("Failed to read protocol specification '{spec}': {error:?}")
40    };
41    let mut proto_file = match File::create(proto) {
42        Ok(proto_file) => proto_file,
43        Err(error) => panic!("Failed to create Rust source file '{proto}': {error:?}")
44    };
45    if let Err(error) = writeln!(proto_file, "// Auto-Generated file. Do not edit.\n#![allow(dead_code)]\n\n{}", code) {
46        panic!("Failed to write Rust source file '{proto}': {error:?}")
47    }
48    if let Err(error) = Command::new("rustfmt").arg(proto).status() {
49        panic!("Failed to run rustfmt on Rust source file '{proto}': {error:?}")
50    }
51}