xml-stinks

Crates.ioxml-stinks
lib.rsxml-stinks
version0.1.0
sourcesrc
created_at2023-05-14 17:32:02.888097
updated_at2023-05-14 17:32:02.888097
descriptionPowerful & easy manual XML deserialization using quick-xml
homepage
repositoryhttps://git.hampusmat.com/xml-stinks
max_upload_size
id864394
size64,374
(HampusMat)

documentation

README

XML-Stinks

Powerful, fast & easy manual XML deserialization using abstractions over quick-xml.

Example usage

use std::convert::Infallible;

use xml_stinks::deserializer::buffered::Buffered as BufferedDeserializer;
use xml_stinks::deserializer::{Deserializer, IgnoreEnd};
use xml_stinks::tagged::TagStart;
use xml_stinks::DeserializeTagged;

let mut deserializer =
    BufferedDeserializer::new("<foo>Baz<bar>DF</bar></foo>".as_bytes());

let foo = deserializer.de_tag::<Foo>("foo", IgnoreEnd::No).unwrap();

assert_eq!(&foo.name, "Baz");
assert_eq!(foo.bar.num, 223);

struct Foo
{
    name: String,
    bar: Bar,
}

impl DeserializeTagged for Foo
{
    type Error = Infallible;

    fn deserialize<TDeserializer: Deserializer>(
        start: &TagStart,
        deserializer: &mut TDeserializer,
    ) -> Result<Self, Self::Error>
    {
        let name = deserializer.de_text().unwrap();

        let bar = deserializer.de_tag::<Bar>("bar", IgnoreEnd::No).unwrap();

        Ok(Self { name, bar })
    }
}

struct Bar
{
    num: u32,
}

impl DeserializeTagged for Bar
{
    type Error = Infallible;

    fn deserialize<TDeserializer: Deserializer>(
        start: &TagStart,
        deserializer: &mut TDeserializer,
    ) -> Result<Self, Self::Error>
    {
        let num = u32::from_str_radix(&deserializer.de_text().unwrap(), 16).unwrap();

        Ok(Self { num })
    }
}
Commit count: 0

cargo fmt