pub struct IdHashMapAsMap<T, S = DefaultHashBuilder, A: Allocator = Global> { /* private fields */ }Expand description
Marker type for IdHashMap serialized as a map, for use with serde’s
with attribute.
§Examples
Use with serde’s with attribute:
use iddqd::{
IdHashItem, IdHashMap, id_hash_map::IdHashMapAsMap, id_upcast,
};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
struct Item {
id: u32,
name: String,
}
impl IdHashItem for Item {
type Key<'a> = u32;
fn key(&self) -> Self::Key<'_> {
self.id
}
id_upcast!();
}
#[derive(Serialize, Deserialize)]
struct Config {
#[serde(with = "IdHashMapAsMap")]
items: IdHashMap<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, S, A> IdHashMapAsMap<T, S, A>where
S: Clone + BuildHasher,
A: Allocator,
impl<T, S, A> IdHashMapAsMap<T, S, A>where
S: Clone + BuildHasher,
A: Allocator,
Sourcepub fn serialize<'a, Ser>(
map: &IdHashMap<T, S, A>,
serializer: Ser,
) -> Result<Ser::Ok, Ser::Error>
pub fn serialize<'a, Ser>( map: &IdHashMap<T, S, A>, serializer: Ser, ) -> Result<Ser::Ok, Ser::Error>
Serializes an IdHashMap as a JSON object/map using key() as keys.
Sourcepub fn deserialize<'de, D>(
deserializer: D,
) -> Result<IdHashMap<T, S, A>, D::Error>where
T: IdHashItem + Deserialize<'de> + Debug,
S: Default,
A: Clone + Default,
D: Deserializer<'de>,
pub fn deserialize<'de, D>(
deserializer: D,
) -> Result<IdHashMap<T, S, A>, D::Error>where
T: IdHashItem + Deserialize<'de> + Debug,
S: Default,
A: Clone + Default,
D: Deserializer<'de>,
Deserializes an IdHashMap from a JSON object/map.
Auto Trait Implementations§
impl<T, S, A> Freeze for IdHashMapAsMap<T, S, A>
impl<T, S, A> RefUnwindSafe for IdHashMapAsMap<T, S, A>
impl<T, S, A> Send for IdHashMapAsMap<T, S, A>
impl<T, S, A> Sync for IdHashMapAsMap<T, S, A>
impl<T, S, A> Unpin for IdHashMapAsMap<T, S, A>
impl<T, S, A> UnwindSafe for IdHashMapAsMap<T, S, A>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more