IdOrdMapAsMap

Struct IdOrdMapAsMap 

Source
pub struct IdOrdMapAsMap<T> { /* private fields */ }
Expand description

Marker type for IdOrdMap serialized as a map, for use with serde’s with attribute.

§Examples

Use with serde’s with attribute:

use iddqd::{IdOrdItem, IdOrdMap, id_ord_map::IdOrdMapAsMap, id_upcast};
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
struct Item {
    id: u32,
    name: String,
}

impl IdOrdItem for Item {
    type Key<'a> = u32;
    fn key(&self) -> Self::Key<'_> {
        self.id
    }
    id_upcast!();
}

#[derive(Serialize, Deserialize)]
struct Config {
    #[serde(with = "IdOrdMapAsMap")]
    items: IdOrdMap<Item>,
}

§Requirements

  • For serialization, the key type must implement Serialize.
  • For JSON serialization, the key should be string-like or convertible to a string key.

Implementations§

Source§

impl<T> IdOrdMapAsMap<T>

Source

pub fn serialize<'a, Ser>( map: &IdOrdMap<T>, serializer: Ser, ) -> Result<Ser::Ok, Ser::Error>
where T: 'a + IdOrdItem + Serialize, T::Key<'a>: Serialize, Ser: Serializer,

Serializes an IdOrdMap as a JSON object/map using key() as keys.

Source

pub fn deserialize<'de, D>(deserializer: D) -> Result<IdOrdMap<T>, D::Error>
where T: IdOrdItem + Deserialize<'de> + Debug, D: Deserializer<'de>,

Deserializes an IdOrdMap from a JSON object/map.

Auto Trait Implementations§

§

impl<T> Freeze for IdOrdMapAsMap<T>

§

impl<T> RefUnwindSafe for IdOrdMapAsMap<T>

§

impl<T> Send for IdOrdMapAsMap<T>

§

impl<T> Sync for IdOrdMapAsMap<T>

§

impl<T> Unpin for IdOrdMapAsMap<T>

§

impl<T> UnwindSafe for IdOrdMapAsMap<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.