Skip to content

Commit 645dd01

Browse files
committed
Auto merge of #33085 - fitzgen:make-enumerate-example-more-clear, r=steveklabnik
Make the `Iterator::enumerate` doc example more clear The example uses integers for the value being iterated over, but the indices added by `enumerate` are also integers, so I always end up double taking and thinking harder than I should when parsing the documentation. I also always forget which order the index and value are in the tuple so I frequently hit this stumbling block. This commit changes the documentation to iterate over characters so that it is immediately obvious which part of the tuple is the index and which is the value.
2 parents 1930483 + e078667 commit 645dd01

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/libcore/iter/iterator.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -598,13 +598,13 @@ pub trait Iterator {
598598
/// # Examples
599599
///
600600
/// ```
601-
/// let a = [1, 2, 3];
601+
/// let a = ['a', 'b', 'c'];
602602
///
603603
/// let mut iter = a.iter().enumerate();
604604
///
605-
/// assert_eq!(iter.next(), Some((0, &1)));
606-
/// assert_eq!(iter.next(), Some((1, &2)));
607-
/// assert_eq!(iter.next(), Some((2, &3)));
605+
/// assert_eq!(iter.next(), Some((0, &'a')));
606+
/// assert_eq!(iter.next(), Some((1, &'b')));
607+
/// assert_eq!(iter.next(), Some((2, &'c')));
608608
/// assert_eq!(iter.next(), None);
609609
/// ```
610610
#[inline]
@@ -2109,4 +2109,3 @@ impl<'a, I: Iterator + ?Sized> Iterator for &'a mut I {
21092109
fn next(&mut self) -> Option<I::Item> { (**self).next() }
21102110
fn size_hint(&self) -> (usize, Option<usize>) { (**self).size_hint() }
21112111
}
2112-

0 commit comments

Comments
 (0)