about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2015-03-27 14:58:22 -0400
committerSteve Klabnik <steve@steveklabnik.com>2015-03-27 18:32:46 -0400
commit59d417a64a49614210cc28bfc7f16a97032bfa7a (patch)
treee73391533988636eb799a1ae6420bef9b2372513
parent242ed0b7c0f6a21096f2cc3e1ad1bdb176d02545 (diff)
downloadrust-59d417a64a49614210cc28bfc7f16a97032bfa7a.tar.gz
rust-59d417a64a49614210cc28bfc7f16a97032bfa7a.zip
Note that zip and enumerate are similar
Fixes #22716
-rw-r--r--src/libcore/iter.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs
index 5f5b8ef73ef..da89dda3af1 100644
--- a/src/libcore/iter.rs
+++ b/src/libcore/iter.rs
@@ -244,6 +244,20 @@ pub trait IteratorExt: Iterator + Sized {
     /// 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 @@ pub trait IteratorExt: Iterator + Sized {
     /// 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
     ///
     /// ```