swrs/
util.rs

1/// Simply contains utilities for the library to function
2
3/// A struct that counts every `next`
4pub struct CountingIterator<I> {
5    iter: I,
6    count: u32,
7}
8
9impl<I> CountingIterator<I>
10where I: Iterator {
11    pub fn new(iterator: I) -> CountingIterator<I> {
12        CountingIterator {
13            iter: iterator,
14            count: 0
15        }
16    }
17
18    pub fn get_count(&self) -> u32 { self.count }
19}
20
21impl<I> Iterator for CountingIterator<I>
22where
23    I: Iterator {
24    type Item = <I as Iterator>::Item;
25
26    fn next(&mut self) -> Option<Self::Item> {
27        self.count += 1;
28        self.iter.next()
29    }
30}