SerdeMapStrategy

Trait SerdeMapStrategy 

Source
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§

Source

type Des

deserialized type

Source

type SerRet<'s>: Serialize where Ser: 's

serialization return type

Required Methods§

Source

fn serialize(d: &Self::Des) -> Self::SerRet<'_>

Source

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.

Implementors§

Source§

impl<Ser: Serialize> SerdeMapStrategy<Ser> for Linear

Source§

type Des = Ser

Source§

type SerRet<'s> = &'s Ser where Ser: 's