to_string

Function to_string 

Source
pub fn to_string<T: Facet<'static>>(value: &T) -> Result<String, XmlError>
Expand description

Serialize a value of type T to an XML string.

The type T must be a struct where fields are marked with XML attributes like #[facet(xml::element)], #[facet(xml::attribute)], or #[facet(xml::text)].

ยงExample

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

let person = Person { id: 42, name: "Alice".into() };
let xml = to_string(&person)?;
assert_eq!(xml, r#"<Person id="42"><name>Alice</name></Person>"#);