pub trait SerdeMapStrategy<Ser>: Sized {
type Des;
type SerRet<'s>: Serialize
where Ser: 's;
// Required methods
fn serialize(d: &Self::Des) -> Self::SerRet<'_>;
fn deserialize<E: Error>(s: Ser) -> Result<Self::Des, E>;
}Expand description
Helps to process data at the serialization/deserialization stage, before saving to the inner Vec.
Example:
use serde::de::Error;
use serde_map::{SerdeMap, SerdeMapStrategy};
struct StringStrategy;
impl SerdeMapStrategy<String> for StringStrategy {
type Des = i64; // deserialized type
type SerRet<'s> = String; // serialization return type
fn serialize(d: &i64) -> Self::SerRet<'_> {
d.to_string()
}
fn deserialize<E: Error>(s: String) -> Result<Self::Des, E> {
s.parse().map_err(Error::custom)
}
}
type SerdeMapString<V> = SerdeMap<String, V, StringStrategy>; // note that `K` here is `String`
// but the inner `Vec` will contain only `i64`Required Associated Types§
Required Methods§
fn serialize(d: &Self::Des) -> Self::SerRet<'_>
fn deserialize<E: Error>(s: Ser) -> Result<Self::Des, E>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.