iterator_ext/
map_err.rs

1use crate::common::*;
2
3#[derive(Debug)]
4pub struct MapErr<I, F> {
5    pub(super) iter: I,
6    pub(super) f: F,
7}
8
9impl<I, F, T, Ein, Eout> Iterator for MapErr<I, F>
10where
11    I: Iterator<Item = Result<T, Ein>>,
12    F: FnMut(Ein) -> Eout,
13{
14    type Item = Result<T, Eout>;
15
16    fn next(&mut self) -> Option<Self::Item> {
17        match self.iter.next() {
18            Some(Ok(item)) => Some(Ok(item)),
19            Some(Err(err)) => Some(Err((self.f)(err))),
20            None => None,
21        }
22    }
23}