Skip to content

Commit e58f057

Browse files
committed
Auto merge of #23789 - steveklabnik:gh22716, r=alexcrichton
Fixes #22716
2 parents 5520801 + 59d417a commit e58f057

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/libcore/iter.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,20 @@ pub trait IteratorExt: Iterator + Sized {
244244
/// assert_eq!(it.next().unwrap(), (&0, &1));
245245
/// assert!(it.next().is_none());
246246
/// ```
247+
///
248+
/// `zip` can provide similar functionality to `enumerate`:
249+
///
250+
/// ```
251+
/// for pair in "foo".chars().enumerate() {
252+
/// println!("{:?}", pair);
253+
/// }
254+
///
255+
/// for pair in (0..).zip("foo".chars()) {
256+
/// println!("{:?}", pair);
257+
/// }
258+
/// ```
259+
///
260+
/// both produce the same output.
247261
#[inline]
248262
#[stable(feature = "rust1", since = "1.0.0")]
249263
fn zip<U: Iterator>(self, other: U) -> Zip<Self, U> {
@@ -313,6 +327,9 @@ pub trait IteratorExt: Iterator + Sized {
313327
/// Creates an iterator that yields a pair of the value returned by this
314328
/// iterator plus the current index of iteration.
315329
///
330+
/// `enumerate` keeps its count as a `usize`. If you want to count by a
331+
/// different sized integer, the `zip` function provides similar functionality.
332+
///
316333
/// # Examples
317334
///
318335
/// ```

0 commit comments

Comments
 (0)