]>
git.proxmox.com Git - rustc.git/blob - vendor/itertools/src/zip_eq_impl.rs
3 /// An iterator which iterates two other iterators simultaneously
5 /// See [`.zip_eq()`](../trait.Itertools.html#method.zip_eq) for more information.
6 #[derive(Clone, Debug)]
7 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
8 pub struct ZipEq
<I
, J
> {
13 /// Iterate `i` and `j` in lock step.
15 /// **Panics** if the iterators are not of the same length.
17 /// `IntoIterator` enabled version of `i.zip_eq(j)`.
20 /// use itertools::zip_eq;
22 /// let data = [1, 2, 3, 4, 5];
23 /// for (a, b) in zip_eq(&data[..data.len() - 1], &data[1..]) {
27 pub fn zip_eq
<I
, J
>(i
: I
, j
: J
) -> ZipEq
<I
::IntoIter
, J
::IntoIter
>
28 where I
: IntoIterator
,
37 impl<I
, J
> Iterator
for ZipEq
<I
, J
>
41 type Item
= (I
::Item
, J
::Item
);
43 fn next(&mut self) -> Option
<Self::Item
> {
44 match (self.a
.next(), self.b
.next()) {
46 (Some(a
), Some(b
)) => Some((a
, b
)),
47 (None
, Some(_
)) | (Some(_
), None
) =>
48 panic
!("itertools: .zip_eq() reached end of one iterator before the other")
52 fn size_hint(&self) -> (usize, Option
<usize>) {
53 size_hint
::min(self.a
.size_hint(), self.b
.size_hint())
57 impl<I
, J
> ExactSizeIterator
for ZipEq
<I
, J
>
58 where I
: ExactSizeIterator
,