1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#[cfg(feature = "validation")]
pub mod validation;
use crate::{Archive, Fallible, Serialize};
#[derive(Debug, Eq)]
#[cfg_attr(feature = "strict", repr(C))]
pub struct Entry<K, V> {
pub key: K,
pub value: V,
}
impl<K: Archive, V: Archive> Archive for Entry<&'_ K, &'_ V> {
type Archived = Entry<K::Archived, V::Archived>;
type Resolver = (K::Resolver, V::Resolver);
#[inline]
unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) {
let (fp, fo) = out_field!(out.key);
self.key.resolve(pos + fp, resolver.0, fo);
let (fp, fo) = out_field!(out.value);
self.value.resolve(pos + fp, resolver.1, fo);
}
}
impl<K: Serialize<S>, V: Serialize<S>, S: Fallible + ?Sized> Serialize<S> for Entry<&'_ K, &'_ V> {
#[inline]
fn serialize(&self, serializer: &mut S) -> Result<Self::Resolver, S::Error> {
Ok((
self.key.serialize(serializer)?,
self.value.serialize(serializer)?,
))
}
}
impl<K, V, UK, UV> PartialEq<Entry<UK, UV>> for Entry<K, V>
where
K: PartialEq<UK>,
V: PartialEq<UV>,
{
#[inline]
fn eq(&self, other: &Entry<UK, UV>) -> bool {
self.key.eq(&other.key) && self.value.eq(&other.value)
}
}