Function to_vec

Source
pub fn to_vec<T: AsXml>(xso: &T) -> Result<Vec<u8>, Error>
Expand description

§Serialize a value to UTF-8-encoded XML

This function takes xso, converts it into XML using its AsXml implementation and serialises the resulting XML events into a Vec<u8>.

If serialisation fails, an error is returned instead.

§Example

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

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