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
1 changed files with 3 additions and 16 deletions
|
@ -1570,24 +1570,13 @@ pub struct Map<I, F> {
|
||||||
f: 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")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<B, I: Iterator, F> Iterator for Map<I, F> where F: FnMut(I::Item) -> B {
|
impl<B, I: Iterator, F> Iterator for Map<I, F> where F: FnMut(I::Item) -> B {
|
||||||
type Item = B;
|
type Item = B;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next(&mut self) -> Option<B> {
|
fn next(&mut self) -> Option<B> {
|
||||||
let next = self.iter.next();
|
self.iter.next().map(|a| (self.f)(a))
|
||||||
self.do_map(next)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1602,8 +1591,7 @@ impl<B, I: DoubleEndedIterator, F> DoubleEndedIterator for Map<I, F> where
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next_back(&mut self) -> Option<B> {
|
fn next_back(&mut self) -> Option<B> {
|
||||||
let next = self.iter.next_back();
|
self.iter.next_back().map(|a| (self.f)(a))
|
||||||
self.do_map(next)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1618,8 +1606,7 @@ impl<B, I: RandomAccessIterator, F> RandomAccessIterator for Map<I, F> where
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn idx(&mut self, index: usize) -> Option<B> {
|
fn idx(&mut self, index: usize) -> Option<B> {
|
||||||
let elt = self.iter.idx(index);
|
self.iter.idx(index).map(|a| (self.f)(a))
|
||||||
self.do_map(elt)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue