Deserialization of SVD file using serde-xml-rs


#1

Hi,
I come from C/C++ world where I have developed xml parser for SVD based on visitor pattern. However, I’m now rewritting the parser in Rust using serde-xml-rs crate and I’ve run into several issues.

The structure of the SVD is defined by ARM [http://www.keil.com/pack/doc/CMSIS/SVD/html/svd_Format_pg.html]

The first issue is with parsing unsigned numbers:

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct Field {
    name: String,
    description: String,
    bit_offset: u8,
    bit_width: u8
}

// Tests
let data = r#"
<field>
<name>MODER15</name>
<description>Port x configuration bits (y =
0..15)</description>
<bitOffset>30</bitOffset>
<bitWidth>2</bitWidth>
</field>
"#;


let field: Field = serde_xml_rs::deserialize(data.as_bytes()).unwrap();

assert_eq!(field.name, "MODER15");
assert_eq!(field.description, "Port x configuration bits (y = 0..15)");
assert_eq!(field.bit_offset, 30);
assert_eq!(field.bit_width, 2);

But I get following error: value: invalid type: string “30”, expected u8’.

When I use type i32 it works without any error? Any idea why?