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
pub mod cursor_list;
pub mod cursor_pair;
pub trait Cursor<K, V, T, R> {
type Storage;
fn key_valid(&self, storage: &Self::Storage) -> bool;
fn val_valid(&self, storage: &Self::Storage) -> bool;
fn key<'a>(&self, storage: &'a Self::Storage) -> &'a K;
fn val<'a>(&self, storage: &'a Self::Storage) -> &'a V;
fn get_key<'a>(&self, storage: &'a Self::Storage) -> Option<&'a K> {
if self.key_valid(storage) { Some(self.key(storage)) } else { None }
}
fn get_val<'a>(&self, storage: &'a Self::Storage) -> Option<&'a V> {
if self.val_valid(storage) { Some(self.val(storage)) } else { None }
}
fn map_times<L: FnMut(&T, R)>(&mut self, storage: &Self::Storage, logic: L);
fn step_key(&mut self, storage: &Self::Storage);
fn seek_key(&mut self, storage: &Self::Storage, key: &K);
fn step_val(&mut self, storage: &Self::Storage);
fn seek_val(&mut self, storage: &Self::Storage, val: &V);
fn rewind_keys(&mut self, storage: &Self::Storage);
fn rewind_vals(&mut self, storage: &Self::Storage);
}
pub trait CursorDebug<K: Clone, V: Clone, T: Clone, R: Clone> : Cursor<K, V, T, R> {
fn to_vec(&mut self, storage: &Self::Storage) -> Vec<((K, V), Vec<(T, R)>)> {
let mut out = Vec::new();
self.rewind_keys(storage);
self.rewind_vals(storage);
while self.key_valid(storage) {
while self.val_valid(storage) {
let mut kv_out = Vec::new();
self.map_times(storage, |ts, r| {
kv_out.push((ts.clone(), r));
});
out.push(((self.key(storage).clone(), self.val(storage).clone()), kv_out));
self.step_val(storage);
}
self.step_key(storage);
}
out
}
}
impl<C, K: Clone, V: Clone, T: Clone, R: Clone> CursorDebug<K, V, T, R> for C where C: Cursor<K, V, T, R> { }