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
use ArgdataRef;
use ReadError;
pub trait Map<'d> {
fn iter_map_next<'a>(
&'a self,
cookie: &mut usize,
) -> Option<Result<(ArgdataRef<'a, 'd>, ArgdataRef<'a, 'd>), ReadError>>
where
'd: 'a;
}
impl<'a, 'd: 'a> Map<'d> + 'a {
pub fn iter_map(&'a self) -> MapIterator<'a, 'd> {
MapIterator {
map: self,
cookie: 0,
}
}
}
pub struct MapIterator<'a, 'd: 'a> {
map: &'a (Map<'d> + 'a),
cookie: usize,
}
impl<'a, 'd: 'a> Iterator for MapIterator<'a, 'd> {
type Item = Result<(ArgdataRef<'a, 'd>, ArgdataRef<'a, 'd>), ReadError>;
fn next(&mut self) -> Option<Self::Item> {
self.map.iter_map_next(&mut self.cookie)
}
}