pub struct TriHashMapAsMap<T, S = DefaultHashBuilder, A: Allocator = Global> { /* private fields */ }Expand description
Marker type for TriHashMap serialized as a map, for use with serde’s
with attribute.
The key type Self::K1 is used as the map key.
§Examples
Use with serde’s with attribute:
use iddqd::{
TriHashItem, TriHashMap, tri_hash_map::TriHashMapAsMap, tri_upcast,
};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
struct Item {
id: u32,
name: String,
email: String,
}
impl TriHashItem for Item {
type K1<'a> = u32;
type K2<'a> = &'a str;
type K3<'a> = &'a str;
fn key1(&self) -> Self::K1<'_> {
self.id
}
fn key2(&self) -> Self::K2<'_> {
&self.name
}
fn key3(&self) -> Self::K3<'_> {
&self.email
}
tri_upcast!();
}
#[derive(Serialize, Deserialize)]
struct Config {
#[serde(with = "TriHashMapAsMap")]
items: TriHashMap<Item>,
}§Requirements
- For serialization, the key type
K1must implementSerialize. - For JSON serialization,
K1should be string-like or convertible to a string key.
Implementations§
Source§impl<T, S, A> TriHashMapAsMap<T, S, A>where
S: Clone + BuildHasher,
A: Allocator,
impl<T, S, A> TriHashMapAsMap<T, S, A>where
S: Clone + BuildHasher,
A: Allocator,
Sourcepub fn serialize<'a, Ser>(
map: &TriHashMap<T, S, A>,
serializer: Ser,
) -> Result<Ser::Ok, Ser::Error>
pub fn serialize<'a, Ser>( map: &TriHashMap<T, S, A>, serializer: Ser, ) -> Result<Ser::Ok, Ser::Error>
Serializes a TriHashMap as a JSON object/map using key1() as keys.
Sourcepub fn deserialize<'de, D>(
deserializer: D,
) -> Result<TriHashMap<T, S, A>, D::Error>where
T: TriHashItem + Deserialize<'de> + Debug,
S: Default,
A: Clone + Default,
D: Deserializer<'de>,
pub fn deserialize<'de, D>(
deserializer: D,
) -> Result<TriHashMap<T, S, A>, D::Error>where
T: TriHashItem + Deserialize<'de> + Debug,
S: Default,
A: Clone + Default,
D: Deserializer<'de>,
Deserializes a TriHashMap from a JSON object/map.
Auto Trait Implementations§
impl<T, S, A> Freeze for TriHashMapAsMap<T, S, A>
impl<T, S, A> RefUnwindSafe for TriHashMapAsMap<T, S, A>
impl<T, S, A> Send for TriHashMapAsMap<T, S, A>
impl<T, S, A> Sync for TriHashMapAsMap<T, S, A>
impl<T, S, A> Unpin for TriHashMapAsMap<T, S, A>
impl<T, S, A> UnwindSafe for TriHashMapAsMap<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