Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8063833

Browse files
committed
support in-place collect for MapWhile adapters
1 parent 55d1296 commit 8063833

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

library/alloc/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#![feature(split_inclusive)]
1616
#![feature(binary_heap_retain)]
1717
#![feature(inplace_iteration)]
18+
#![feature(iter_map_while)]
1819

1920
use std::collections::hash_map::DefaultHasher;
2021
use std::hash::{Hash, Hasher};

library/alloc/tests/vec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ fn test_from_iter_specialization_with_iterator_adapters() {
819819
.map(|i| i.0 + i.1)
820820
.zip(std::iter::repeat(1usize))
821821
.map(|(a, b)| a + b)
822+
.map_while(Option::Some)
822823
.peekable()
823824
.skip(1)
824825
.map(|e| std::num::NonZeroUsize::new(e));

library/core/src/iter/adapters/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,6 +2191,27 @@ where
21912191
}
21922192
}
21932193

2194+
#[unstable(issue = "none", feature = "inplace_iteration")]
2195+
unsafe impl<S: Iterator, B, I: Iterator, P> SourceIter for MapWhile<I, P>
2196+
where
2197+
P: FnMut(I::Item) -> Option<B>,
2198+
I: SourceIter<Source = S>,
2199+
{
2200+
type Source = S;
2201+
2202+
#[inline]
2203+
unsafe fn as_inner(&mut self) -> &mut S {
2204+
// Safety: unsafe function forwarding to unsafe function with the same requirements
2205+
unsafe { SourceIter::as_inner(&mut self.iter) }
2206+
}
2207+
}
2208+
2209+
#[unstable(issue = "none", feature = "inplace_iteration")]
2210+
unsafe impl<B, I: InPlaceIterable, P> InPlaceIterable for MapWhile<I, P> where
2211+
P: FnMut(I::Item) -> Option<B>
2212+
{
2213+
}
2214+
21942215
/// An iterator that skips over `n` elements of `iter`.
21952216
///
21962217
/// This `struct` is created by the [`skip`] method on [`Iterator`]. See its

0 commit comments

Comments
 (0)