from_str

Function from_str 

Source
pub fn from_str<'input, 'facet, T>(xml: &'input str) -> Result<T, XmlError>
where T: Facet<'facet>, 'input: 'facet,
Expand description

Deserialize an XML string into a value of type T.

ยงExample

use facet::Facet;
use facet_xml as xml;

#[derive(Facet, Debug, PartialEq)]
struct Person {
    #[facet(xml::attribute)]
    id: u32,
    #[facet(xml::element)]
    name: String,
}

let xml_str = r#"<Person id="42"><name>Alice</name></Person>"#;
let person: Person = facet_xml::from_str(xml_str).unwrap();
assert_eq!(person.name, "Alice");
assert_eq!(person.id, 42);