Skip to content

Commit 0f122e1

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 3d5e9f1 commit 0f122e1

File tree

1 file changed

+24
-1
lines changed
  • library/core/src/iter/adapters

1 file changed

+24
-1
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use crate::cmp;
22
use crate::fmt::{self, Debug};
33

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

69
/// An iterator that iterates two other iterators simultaneously.
710
///
@@ -327,6 +330,26 @@ where
327330
{
328331
}
329332

333+
// Arbitrarily selects the left side of the zip iteration as extractable "source"
334+
// it would require negative trait bounds to be able to try both
335+
#[unstable(issue = "0", feature = "inplace_iteration")]
336+
unsafe impl<S, A, B> SourceIter for Zip<A, B>
337+
where
338+
A: SourceIter<Source = S>,
339+
B: Iterator,
340+
S: Iterator,
341+
{
342+
type Source = S;
343+
344+
#[inline]
345+
fn as_inner(&mut self) -> &mut S {
346+
SourceIter::as_inner(&mut self.a)
347+
}
348+
}
349+
350+
#[unstable(issue = "0", feature = "inplace_iteration")]
351+
unsafe impl<A: InPlaceIterable, B: Iterator> InPlaceIterable for Zip<A, B> {}
352+
330353
#[stable(feature = "rust1", since = "1.0.0")]
331354
impl<A: Debug, B: Debug> Debug for Zip<A, B> {
332355
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

0 commit comments

Comments
 (0)