Function transform

Source
pub fn transform<T: FromXml, F: AsXml>(from: &F) -> Result<T, Error>
Expand description

§Transform a value into another value via XML

This function takes from, converts it into XML using its AsXml implementation 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 header provided by from, Error::TypeMismatch is returned.

§Example

#[derive(AsXml)]
#[xml(namespace = "urn:example", name = "foo")]
struct Source {
    #[xml(attribute = "xml:lang")]
    lang: &'static str,
}

#[derive(FromXml, PartialEq, Debug)]
#[xml(namespace = "urn:example", name = "foo")]
struct Dest {
    #[xml(lang)]
    lang: Option<String>,
}

assert_eq!(
    Dest { lang: Some("en".to_owned()) },
    transform(&Source { lang: "en" }).unwrap(),
);