]> git.lizzy.rs Git - rust.git/commitdiff
Note that zip and enumerate are similar
authorSteve Klabnik <steve@steveklabnik.com>
Fri, 27 Mar 2015 18:58:22 +0000 (14:58 -0400)
committerSteve Klabnik <steve@steveklabnik.com>
Fri, 27 Mar 2015 22:32:46 +0000 (18:32 -0400)
Fixes #22716

src/libcore/iter.rs

index 5f5b8ef73ef54edf1702e92c64369b5e318a38d6..da89dda3af191085a7c82c05e68a2ca976f69adc 100644 (file)
@@ -244,6 +244,20 @@ fn chain<U>(self, other: U) -> Chain<Self, U> where
     /// assert_eq!(it.next().unwrap(), (&0, &1));
     /// assert!(it.next().is_none());
     /// ```
+    ///
+    /// `zip` can provide similar functionality to `enumerate`:
+    ///
+    /// ```
+    /// for pair in "foo".chars().enumerate() {
+    ///     println!("{:?}", pair);
+    /// }
+    ///
+    /// for pair in (0..).zip("foo".chars()) {
+    ///     println!("{:?}", pair);
+    /// }
+    /// ```
+    ///
+    /// both produce the same output.
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
     fn zip<U: Iterator>(self, other: U) -> Zip<Self, U> {
@@ -313,6 +327,9 @@ fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F> where
     /// Creates an iterator that yields a pair of the value returned by this
     /// iterator plus the current index of iteration.
     ///
+    /// `enumerate` keeps its count as a `usize`. If you want to count by a
+    /// different sized integer, the `zip` function provides similar functionality.
+    ///
     /// # Examples
     ///
     /// ```