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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use Prefixed;
use Shared;
use Read;
// TODO: can we do this without copying every time we prefix the key? can
// possibly change Store methods to generically support iterator-based
// concatenated keys, maybe via a Key type.
/// A store wrapper which can be used to create multiple substores, which all
/// read from and write to the same underlying store with a unique prefix per
/// substore.
// impl<'a, 'b: 'a> super::Iter<'a, 'b> for Substore<super::WriteCache<super::NullStore>> {
// type Iter = Iter<'a, 'b, <super::WriteCache<super::NullStore> as Iter<'a, 'b>>::Iter>;
// fn iter_from(&'a self, start: &[u8]) -> Self::Iter {
// let mut key = Vec::with_capacity(start.len() + 1);
// key.push(self.index);
// key.extend(start);
// Iter {
// store: self.store.clone(),
// key: Some(key),
// index: self.index,
// phantom_a: std::marker::PhantomData,
// phantom_b: std::marker::PhantomData,
// }
// }
// }
// pub struct Iter<'a, 'b: 'a, S>
// where
// S: super::Iter<'a, 'b>,
// {
// store: Rc<RefCell<S>>,
// key: Option<Vec<u8>>,
// index: u8,
// phantom_a: std::marker::PhantomData<&'a u8>,
// phantom_b: std::marker::PhantomData<&'b u8>,
// }
// impl<'a, 'b: 'a, S> Iterator for Iter<'a, 'b, S>
// where
// S: super::Iter<'a, 'b>,
// {
// type Item = (&'b [u8], &'b [u8]);
// fn next(&mut self) -> Option<Self::Item> {
// if self.key.is_none() {
// return None;
// }
// let mut key = self.key.as_mut().unwrap();
// let store = self.store.borrow();
// let mut iter = store.iter_from(key.as_slice());
// let maybe_entry = iter.next();
// iter.next().map(|(next_key, _)| {
// if next_key[0] != self.index {
// self.key.take();
// } else {
// key.resize(1, 0);
// key.extend(next_key);
// }
// });
// match maybe_entry {
// None => None,
// Some((key, value)) if key[0] > self.index => None,
// Some((key, value)) => Some((&key[1..], value)),
// }
// }
// }