Skip to content

Commit

Permalink
Rollup merge of #92899 - cameron1024:zip-docs, r=dtolnay
Browse files Browse the repository at this point in the history
Mention std::iter::zip in Iterator::zip docs

Closes #91960

I'm not sure about the wording. I think it's alright, but happy to change.
  • Loading branch information
matthiaskrgr authored Jan 27, 2022
2 parents 4af3930 + 857ea1e commit 54f3578
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,44 @@ pub trait Iterator {
/// assert_eq!((2, 'o'), zipper[2]);
/// ```
///
/// If both iterators have roughly equivalent syntax, it may me more readable to use [`zip`]:
///
/// ```
/// use std::iter::zip;
///
/// let a = [1, 2, 3];
/// let b = [2, 3, 4];
///
/// let mut zipped = zip(
/// a.into_iter().map(|x| x * 2).skip(1),
/// b.into_iter().map(|x| x * 2).skip(1),
/// );
///
/// assert_eq!(zipped.next(), Some((4, 6)));
/// assert_eq!(zipped.next(), Some((6, 8)));
/// assert_eq!(zipped.next(), None);
/// ```
///
/// compared to:
///
/// ```
/// # let a = [1, 2, 3];
/// # let b = [2, 3, 4];
/// #
/// let mut zipped = a
/// .into_iter()
/// .map(|x| x * 2)
/// .skip(1)
/// .zip(b.into_iter().map(|x| x * 2).skip(1));
/// #
/// # assert_eq!(zipped.next(), Some((4, 6)));
/// # assert_eq!(zipped.next(), Some((6, 8)));
/// # assert_eq!(zipped.next(), None);
/// ```
///
/// [`enumerate`]: Iterator::enumerate
/// [`next`]: Iterator::next
/// [`zip`]: crate::iter::zip
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
fn zip<U>(self, other: U) -> Zip<Self, U::IntoIter>
Expand Down

0 comments on commit 54f3578

Please sign in to comment.