from_slice_owned

Function from_slice_owned 

Source
pub fn from_slice_owned<T: Facet<'static>>(xml: &[u8]) -> Result<T, XmlError>
Expand description

Deserialize an XML byte slice into an owned type.

This variant does not require the input to outlive the result, making it suitable for deserializing from temporary buffers (e.g., HTTP request bodies).

Types containing &str fields cannot be deserialized with this function; use String or Cow<str> instead.

ยงExample

use facet::Facet;
use facet_xml as xml;

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

let xml_bytes = b"<Person id=\"42\"><name>Alice</name></Person>";
let person: Person = xml::from_slice_owned(xml_bytes).unwrap();
assert_eq!(person.name, "Alice");
assert_eq!(person.id, 42);