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
#[cfg(feature = "core")]
use core::hash::Hash;
use indexmap::IndexMap;
use rkyv::{Archive, Deserialize, Serialize};
#[cfg(feature = "std")]
use std::hash::Hash;
#[derive(Serialize, Deserialize, Archive)]
pub struct ArchivableIndexMap<K: Hash + Ord + Archive, V: Archive> {
entries: Vec<(K, V)>,
}
impl<K: Hash + Ord + Archive + Clone, V: Archive> From<IndexMap<K, V>>
for ArchivableIndexMap<K, V>
{
fn from(it: IndexMap<K, V>) -> Self {
let mut r = Self {
entries: Vec::new(),
};
for (k, v) in it.into_iter() {
r.entries.push((k, v));
}
r
}
}
impl<K: Hash + Ord + Archive + Clone, V: Archive> Into<IndexMap<K, V>>
for ArchivableIndexMap<K, V>
{
fn into(self) -> IndexMap<K, V> {
let mut r = IndexMap::new();
for (k, v) in self.entries.into_iter() {
r.insert(k, v);
}
r
}
}