1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use crate::common::*;

#[derive(Debug)]
pub struct MapErr<I, F> {
    pub(super) iter: I,
    pub(super) f: F,
}

impl<I, F, T, Ein, Eout> Iterator for MapErr<I, F>
where
    I: Iterator<Item = Result<T, Ein>>,
    F: FnMut(Ein) -> Eout,
{
    type Item = Result<T, Eout>;

    fn next(&mut self) -> Option<Self::Item> {
        match self.iter.next() {
            Some(Ok(item)) => Some(Ok(item)),
            Some(Err(err)) => Some(Err((self.f)(err))),
            None => None,
        }
    }
}