serde_xml_rs::ser

Function to_writer

Source
pub fn to_writer<W: Write, S: Serialize>(
    writer: W,
    value: &S,
) -> Result<(), Error>
Expand description

A convenience method for serializing some object to a buffer.

ยงExamples

#[derive(Serialize)]
struct Person {
  name: String,
  age: u32,
}

let mut buffer = Vec::new();
let joe = Person {name: "Joe".to_string(), age: 42};

to_writer(&mut buffer, &joe).unwrap();

let serialized = String::from_utf8(buffer).unwrap();
println!("{}", serialized);