Function from_bytes

Source
pub fn from_bytes<T: FromXml>(buf: &[u8]) -> Result<T, Error>
Expand description

§Parse a value from a byte slice containing XML data

This function parses the XML found in buf, assuming it contains a complete XML document (with optional XML declaration) and builds a T from it (without buffering the tree in memory).

If conversion fails, a Error is returned. In particular, if T expects a different element header than the element header at the root of the document in bytes, Error::TypeMismatch is returned.

§Example

#[derive(FromXml, PartialEq, Debug)]
#[xml(namespace = "urn:example", name = "foo")]
struct Foo {
    #[xml(attribute)]
    a: String,
}

assert_eq!(
    Foo { a: "some-value".to_owned() },
    from_bytes(b"<foo xmlns='urn:example' a='some-value'/>").unwrap(),
);