#deserializer #serde-derive #derive-debug #debugging #string #name #xml-rs

serde-xml-rs2

xml-rs based deserializer for Serde (compatible with 0.9+)

1 unstable release

Uses old Rust 2015

0.3.0 May 31, 2020

#39 in #deserializer

MIT license

50KB
1K SLoC

serde-xml-rs

Build Status

xml-rs based deserializer for Serde (compatible with 0.9+)

Usage

Use serde_xml_rs::deserialize(...) on any type that implements std::io::Read as following:

#[macro_use] extern crate serde_derive;
extern crate serde_xml_rs;

use serde_xml_rs::deserialize;

#[derive(Debug, Deserialize)]
struct Item {
    pub name: String,
    pub source: String
}

#[derive(Debug, Deserialize)]
struct Project {
    pub name: String,

    #[serde(rename = "Item", default)]
    pub items: Vec<Item>
}

#[test]
fn it_works() {
    let s = r##"
        <Project name="my_project">
            <Item name="hello" source="world.rs" />
        </Project>
    "##;
    let project: Project = deserialize(s.as_bytes()).unwrap();
    println!("{:#?}", project);
}

Alternatively, you can use serde_xml_rs::Deserializer to create a deserializer from a preconfigured xml_rs::EventReader.

Parsed representations

Deserializer tries to be as intuitive as possible.

However, there are some edge cases where you might get unexpected errors, so it's best to check out tests for expectations.

Dependencies

~3–8.5MB
~87K SLoC