Simplify OnErr iterator next and next_back

This commit is contained in:
Matthijs Hofstra 2016-10-21 11:02:52 +02:00
parent 174a9b2d40
commit 7a5f5b5061

View file

@ -38,13 +38,7 @@ impl<I, F, T, E> Iterator for OnErr<I, F> where
#[inline] #[inline]
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
match self.iter.next() { self.iter.next().map(|r| r.map_err(|e| { (self.f)(&e); e }))
Some(Err(e)) => {
(self.f)(&e);
Some(Err(e))
},
other => other
}
} }
#[inline] #[inline]
@ -65,13 +59,7 @@ impl<I, F, T, E> DoubleEndedIterator for OnErr<I, F> where
{ {
#[inline] #[inline]
fn next_back(&mut self) -> Option<Self::Item> { fn next_back(&mut self) -> Option<Self::Item> {
match self.iter.next_back() { self.iter.next_back().map(|r| r.map_err(|e| { (self.f)(&e); e }))
Some(Err(e)) => {
(self.f)(&e);
Some(Err(e))
},
other => other
}
} }
} }