support in-place collect for MapWhile adapters

This commit is contained in:
The8472 2020-04-04 18:34:18 +02:00
parent 55d1296a55
commit 80638330f2
3 changed files with 23 additions and 0 deletions

View file

@ -15,6 +15,7 @@
#![feature(split_inclusive)]
#![feature(binary_heap_retain)]
#![feature(inplace_iteration)]
#![feature(iter_map_while)]
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};

View file

@ -819,6 +819,7 @@ fn test_from_iter_specialization_with_iterator_adapters() {
.map(|i| i.0 + i.1)
.zip(std::iter::repeat(1usize))
.map(|(a, b)| a + b)
.map_while(Option::Some)
.peekable()
.skip(1)
.map(|e| std::num::NonZeroUsize::new(e));

View file

@ -2191,6 +2191,27 @@ where
}
}
#[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<S: Iterator, B, I: Iterator, P> SourceIter for MapWhile<I, P>
where
P: FnMut(I::Item) -> Option<B>,
I: SourceIter<Source = S>,
{
type Source = S;
#[inline]
unsafe fn as_inner(&mut self) -> &mut S {
// Safety: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) }
}
}
#[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<B, I: InPlaceIterable, P> InPlaceIterable for MapWhile<I, P> where
P: FnMut(I::Item) -> Option<B>
{
}
/// An iterator that skips over `n` elements of `iter`.
///
/// This `struct` is created by the [`skip`] method on [`Iterator`]. See its