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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use serde::de::DeserializeOwned;
use std::collections::hash_map;
use std::slice;
use crate::serialization::Serializer;
pub struct PickleDbIterator<'a> {
pub(crate) map_iter: hash_map::Iter<'a, String, Vec<u8>>,
pub(crate) serializer: &'a Serializer,
}
impl<'a> Iterator for PickleDbIterator<'a> {
type Item = PickleDbIteratorItem<'a>;
fn next(&mut self) -> Option<Self::Item> {
match self.map_iter.next() {
Some((key, value)) => Some(PickleDbIteratorItem {
key,
value,
serializer: self.serializer,
}),
None => None,
}
}
}
pub struct PickleDbIteratorItem<'a> {
key: &'a str,
value: &'a Vec<u8>,
serializer: &'a Serializer,
}
impl<'a> PickleDbIteratorItem<'a> {
pub fn get_key(&self) -> &str {
self.key
}
pub fn get_value<V>(&self) -> Option<V>
where
V: DeserializeOwned,
{
self.serializer.deserialize_data::<V>(self.value)
}
}
pub struct PickleDbListIterator<'a> {
pub(crate) list_iter: slice::Iter<'a, Vec<u8>>,
pub(crate) serializer: &'a Serializer,
}
impl<'a> Iterator for PickleDbListIterator<'a> {
type Item = PickleDbListIteratorItem<'a>;
fn next(&mut self) -> Option<Self::Item> {
match self.list_iter.next() {
Some(value) => Some(PickleDbListIteratorItem {
value,
serializer: self.serializer,
}),
None => None,
}
}
}
pub struct PickleDbListIteratorItem<'a> {
value: &'a Vec<u8>,
serializer: &'a Serializer,
}
impl<'a> PickleDbListIteratorItem<'a> {
pub fn get_item<V>(&self) -> Option<V>
where
V: DeserializeOwned,
{
self.serializer.deserialize_data(self.value)
}
}