codespawn

Function from_xml

Source
pub fn from_xml(filename: &str) -> Result<RawCode>
Expand description

Reads XML data from file and compiles it into RawCode

ยงExamples

extern crate codespawn;

let raw_code = codespawn::from_xml("examples/sample.xml").unwrap();
Examples found in repository?
examples/xml.rs (line 6)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
fn main()
{
    // generate from XML definition
    let raw_code = codespawn::from_xml("examples/sample.xml").unwrap_or_else(|e| {
        panic!("{}", e);
    });
    // generate from JSON definition
    //let raw_code = codespawn::from_json("examples/sample.json").unwrap_or_else(|e| {
    //    panic!("{}", e);
    //});

    println!("\n*** Language specific configs (if defined):");
    for c in raw_code.configs.iter() {
        println!("{}", c.1);
    }

    println!("*** Structure of raw (unformatted) code data:\n{}", raw_code);
    println!("*** Structure of C++ code generated from raw code data:\n{}", raw_code.to_cpp().unwrap());
    println!("*** Structure of Rust code generated from raw code data:\n{}", raw_code.to_rust().unwrap());
    println!("*** Generated C++ code:\n\n{}", raw_code.to_cpp().unwrap().to_string());
    println!("*** Generated Rust code:\n\n{}", raw_code.to_rust().unwrap().to_string());

    // save generated code to file
    let _ = raw_code.to_cpp().unwrap().to_file("sample.cpp");
    let _ = raw_code.to_rust().unwrap().to_file("sample.rs");
}