diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-01-27 22:32:23 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-27 22:32:23 +0100 |
| commit | 54f357836ec5786fa7f6f08626ee5b692ccb2757 (patch) | |
| tree | 6063de663c841b81f7ad018af73e65d44af3d5ed | |
| parent | 4af3930f28d6e508d84664e7f066430284aa9ea1 (diff) | |
| parent | 857ea1e7eb561928ad06c21503d52f2279ee5d46 (diff) | |
| download | rust-54f357836ec5786fa7f6f08626ee5b692ccb2757.tar.gz rust-54f357836ec5786fa7f6f08626ee5b692ccb2757.zip | |
Rollup merge of #92899 - cameron1024:zip-docs, r=dtolnay
Mention std::iter::zip in Iterator::zip docs Closes https://github.com/rust-lang/rust/issues/91960 I'm not sure about the wording. I think it's alright, but happy to change.
| -rw-r--r-- | library/core/src/iter/traits/iterator.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index 1d947297463..65cadcb6c5a 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -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> |
