Skip to content

Commit 4220852

Browse files
committed
add in-place iteration for Zip
this picks the left hand side as source since it might be more natural to consume that as IntoIter source
1 parent 96c049f commit 4220852

File tree

1 file changed

+24
-1
lines changed
  • src/libcore/iter/adapters

1 file changed

+24
-1
lines changed

src/libcore/iter/adapters/zip.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
use crate::cmp;
44

5-
use super::super::{DoubleEndedIterator, ExactSizeIterator, FusedIterator, Iterator, TrustedLen};
5+
use super::super::{
6+
DoubleEndedIterator, ExactSizeIterator, FusedIterator, InPlaceIterable, Iterator, SourceIter,
7+
TrustedLen,
8+
};
69

710
/// An iterator that iterates two other iterators simultaneously.
811
///
@@ -289,6 +292,26 @@ where
289292
{
290293
}
291294

295+
// Arbitrarily selects the left side of the zip iteration as extractable "source"
296+
// it would require negative trait bounds to be able to try both
297+
#[unstable(issue = "0", feature = "inplace_iteration")]
298+
unsafe impl<S, A, B> SourceIter for Zip<A, B>
299+
where
300+
A: SourceIter<Source = S>,
301+
B: Iterator,
302+
S: Iterator,
303+
{
304+
type Source = S;
305+
306+
#[inline]
307+
fn as_inner(&mut self) -> &mut S {
308+
SourceIter::as_inner(&mut self.a)
309+
}
310+
}
311+
312+
#[unstable(issue = "0", feature = "inplace_iteration")]
313+
unsafe impl<A: InPlaceIterable, B: Iterator> InPlaceIterable for Zip<A, B> {}
314+
292315
/// An iterator whose items are random-accessible efficiently
293316
///
294317
/// # Safety

0 commit comments

Comments
 (0)