/// An iterator which iterates two other iterators simultaneously /// /// See [`.zip_eq()`](crate::Itertools::zip_eq) for more information. #[derive(Clone, Debug)] #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pubstruct ZipEq<I, J> {
a: I,
b: J,
}
/// Iterate `i` and `j` in lock step. /// /// **Panics** if the iterators are not of the same length. /// /// [`IntoIterator`] enabled version of [`Itertools::zip_eq`](crate::Itertools::zip_eq). /// /// ``` /// use itertools::zip_eq; /// /// let data = [1, 2, 3, 4, 5]; /// for (a, b) in zip_eq(&data[..data.len() - 1], &data[1..]) { /// /* loop body */ /// } /// ``` pubfn zip_eq<I, J>(i: I, j: J) -> ZipEq<I::IntoIter, J::IntoIter> where I: IntoIterator,
J: IntoIterator
{
ZipEq {
a: i.into_iter(),
b: j.into_iter(),
}
}
impl<I, J> Iterator for ZipEq<I, J> where I: Iterator,
J: Iterator
{ type Item = (I::Item, J::Item);
fn next(&mutself) -> Option<Self::Item> { match (self.a.next(), self.b.next()) {
(None, None) => None,
(Some(a), Some(b)) => Some((a, b)),
(None, Some(_)) | (Some(_), None) =>
panic!("itertools: .zip_eq() reached end of one iterator before the other")
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.