From f27758e8d7dae117d7989dc555823fc75426fd3e Mon Sep 17 00:00:00 2001 From: cameron Date: Thu, 27 Jan 2022 06:47:52 +0000 Subject: [PATCH 1/2] mention std::iter::zip in Iterator::zip docs --- library/core/src/iter/traits/iterator.rs | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index 1d947297463d9..1132409715ca6 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -514,9 +514,40 @@ pub trait Iterator { /// assert_eq!((2, 'o'), enumerate[2]); /// 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(self, other: U) -> Zip From 857ea1e7eb561928ad06c21503d52f2279ee5d46 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 27 Jan 2022 12:41:03 -0800 Subject: [PATCH 2/2] Touch up PR 92899 Iterator::zip docs --- library/core/src/iter/traits/iterator.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index 1132409715ca6..65cadcb6c5a4f 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -514,9 +514,12 @@ pub trait Iterator { /// assert_eq!((2, 'o'), enumerate[2]); /// 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; + /// use std::iter::zip; + /// /// let a = [1, 2, 3]; /// let b = [2, 3, 4]; /// @@ -529,20 +532,22 @@ pub trait Iterator { /// 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 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); + /// # + /// # assert_eq!(zipped.next(), Some((4, 6))); + /// # assert_eq!(zipped.next(), Some((6, 8))); + /// # assert_eq!(zipped.next(), None); /// ``` /// /// [`enumerate`]: Iterator::enumerate