commit | 0ba6fce7d4929f2855ba09c275eb012edf032677 | [log] [tgz] |
---|---|---|
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Fri Oct 01 16:00:36 2021 +0000 |
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Fri Oct 01 16:00:36 2021 +0000 |
tree | 765cec3e43132e50b6918fae9d51e2001174e69d | |
parent | 242244901480917fe3d564dad6e48d664a78ebc4 [diff] | |
parent | d26db57236a6a37545b4cfa06f0ef13423dd20f9 [diff] |
Snap for 7785160 from d26db57236a6a37545b4cfa06f0ef13423dd20f9 to t-keystone-qcom-release Change-Id: I8b313c7143874968575c358b14f7c24271e95ceb
xml-rs based deserializer for Serde (compatible with 0.9+)
Use serde_xml_rs::from_reader(...)
on any type that implements std::io::Read
as following:
#[macro_use] extern crate serde_derive; extern crate serde; extern crate serde_xml_rs; use serde_xml_rs::from_reader; #[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> } fn main() { let s = r##" <Project name="my_project"> <Item name="hello" source="world.rs" /> </Project> "##; let project: Project = from_reader(s.as_bytes()).unwrap(); println!("{:#?}", project); }
Alternatively, you can use serde_xml_rs::Deserializer
to create a deserializer from a preconfigured xml_rs::EventReader
.
If you have an input of the form <foo abc="xyz">bar</foo>
, and you want to get at thebar
, you can use the special name $value
:
struct Foo { pub abc: String, #[serde(rename = "$value")] pub body: String, }
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.