Auto merge of #22958 - laijs:option_map_for_iter_map, r=alexcrichton
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
This commit is contained in:
commit
6e055c3f00
@ -1570,24 +1570,13 @@ pub struct Map<I, F> {
|
||||
f: F,
|
||||
}
|
||||
|
||||
impl<I: Iterator, F, B> Map<I, F> where F: FnMut(I::Item) -> B {
|
||||
#[inline]
|
||||
fn do_map(&mut self, elt: Option<I::Item>) -> Option<B> {
|
||||
match elt {
|
||||
Some(a) => Some((self.f)(a)),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<B, I: Iterator, F> Iterator for Map<I, F> where F: FnMut(I::Item) -> B {
|
||||
type Item = B;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<B> {
|
||||
let next = self.iter.next();
|
||||
self.do_map(next)
|
||||
self.iter.next().map(|a| (self.f)(a))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -1602,8 +1591,7 @@ impl<B, I: DoubleEndedIterator, F> DoubleEndedIterator for Map<I, F> where
|
||||
{
|
||||
#[inline]
|
||||
fn next_back(&mut self) -> Option<B> {
|
||||
let next = self.iter.next_back();
|
||||
self.do_map(next)
|
||||
self.iter.next_back().map(|a| (self.f)(a))
|
||||
}
|
||||
}
|
||||
|
||||
@ -1618,8 +1606,7 @@ impl<B, I: RandomAccessIterator, F> RandomAccessIterator for Map<I, F> where
|
||||
|
||||
#[inline]
|
||||
fn idx(&mut self, index: usize) -> Option<B> {
|
||||
let elt = self.iter.idx(index);
|
||||
self.do_map(elt)
|
||||
self.iter.idx(index).map(|a| (self.f)(a))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user