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
/// Wrapper for an iterator, counting the current index.
/// Basically allows for the same thing as `enumerate` but not just in one statement.
pub struct TracebackIterator<T>
where
    T: Iterator,
{
    inner_iterator: T,
    current_line: i64,
}

impl<T> TracebackIterator<T>
where
    T: Iterator,
{
    /// Gets the current index of the iterator.
    pub fn current_line(&self) -> i64 {
        self.current_line
    }
}

impl<T> Iterator for TracebackIterator<T>
where
    T: Iterator,
{
    type Item = T::Item;

    fn next(&mut self) -> Option<Self::Item> {
        self.current_line += 1;
        self.inner_iterator.next()
    }
}

impl<T> From<T> for TracebackIterator<T>
where
    T: Iterator,
{
    fn from(inner_iterator: T) -> Self {
        Self {
            inner_iterator,
            current_line: 0,
        }
    }
}