Skip to content
luminventPublic

About

Yet Another Serializer/Deserializer

Resources

Stars

201 stars

Watchers

7 watching

Forks

Latest commit

 

History

425 Commits

Folders and files

Repository files navigation

yaserde   Latest Version

Yet Another Serializer/Deserializer specialized for XML

Goal

This library will support XML de/ser-ializing with all specific features.

Supported types

  • Struct
  • Vec
  • Enum
  • Enum with complex types
  • Option
  • String
  • bool
  • number (u8, i8, u32, i32, f32, f64)

Attributes

  • attribute: this field is defined as an attribute
  • default: defines the default function to init the field
  • flatten: Flatten the contents of the field
  • namespace: defines the namespace of the field
  • rename: be able to rename a field
  • root: rename the based element. Used only at the XML root.
  • skip_serializing: Exclude this field from the serialized output. More details...
  • skip_serializing_if: Skip the serialisation for this field if the condition is true. More details...
  • text: this field match to the text content

Custom De/Ser-rializer

Any type can define a custom deserializer and/or serializer. To implement it, define the implementation of YaDeserialize/YaSerialize

impl YaDeserialize for MyType {
  fn deserialize<R: Read>(reader: &mut yaserde::de::Deserializer<R>) -> yaserde::Result<Self> {
    // deserializer code
  }
}
impl YaSerialize for MyType {
  fn serialize<W: Write>(&self, writer: &mut yaserde::ser::Serializer<W>) -> yaserde::Result<()> {
    // serializer code
  }
}

Errors

Serialization and deserialization return a yaserde::Error:

  • Error::Reader: the XML input is malformed, with its position in the input.
  • Error::Writer: the XML output could not be written.
  • Error::Message: the XML does not match the expected structure, or a value could not be converted. Create one with yaserde::Error::custom(message) in a custom implementation.
  • Error::Field: an error located in a field, with the field's XML name.

Writer errors convert with ?, and String or &str messages convert with .into().

About

Yet Another Serializer/Deserializer

Resources

Stars

201 stars

Watchers

7 watching

Forks

Releases

Packages

Used by

Contributors

Languages