Expand description
§Serde Many
Serde Many enables multiple serialization/deserialization implementations for the same type.
The design ensures seamless integration with the serde crate.
§Design
The core design of this crate revolves around the SerializeMany and DeserializeMany traits.
These traits are similar to serde’s Serialize and Deserialize traits,
but are generic over a marker type, allowing multiple implementations for different markers.
To ensure seamless integration with serde, any type that implements serde’s
Serialize and Deserialize automatically implements
SerializeMany and DeserializeMany for all markers. This means that types which
manually implement SerializeMany and DeserializeMany cannot also implement
serde’s Serialize and Deserialize.
§Derive
Implementing serialization and deserialization by hand can be tedious. To simplify this process,
this crate (with the “derive” feature) provides derive macros to automatically generate implementations
of the SerializeMany and DeserializeMany traits.
The derive macros use the actual serde derive macros under the hood, meaning all of serde’s attributes are supported.
§Example
use serde_many::{DeserializeMany, SerializeMany};
/// Marker for the default serde implementation.
struct Default;
/// Marker for a special serde implementation.
struct Special;
#[derive(SerializeMany, DeserializeMany)]
#[serde_many(default = "Default", special = "Special")] // Declaring the implementation markers.
struct Point {
#[serde(special(rename = "x_value"))]
x: i32,
#[serde(special(rename = "y_value"))]
y: i32,
}Structs§
- AsSerde
- Serde Adapter for Marker-Based Serialization/Deserialization
Traits§
- Deserialize
Many - A trait for deserializing a value with a specific marker type.
- Serialize
Many - A trait for serializing a value with a specific marker type.