Skip to content

Commit 3ebeaf6

Browse files
authored
Rollup merge of #41216 - shahn:iter_pos, r=steveklabnik
Clarify Iterator::position doc Extend the example a little bit to show behaviour better. r? @steveklabnik
2 parents 828ed96 + 316af60 commit 3ebeaf6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/libcore/iter/iterator.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1532,14 +1532,18 @@ pub trait Iterator {
15321532
/// Stopping at the first `true`:
15331533
///
15341534
/// ```
1535-
/// let a = [1, 2, 3];
1535+
/// let a = [1, 2, 3, 4];
15361536
///
15371537
/// let mut iter = a.iter();
15381538
///
1539-
/// assert_eq!(iter.position(|&x| x == 2), Some(1));
1539+
/// assert_eq!(iter.position(|&x| x >= 2), Some(1));
15401540
///
15411541
/// // we can still use `iter`, as there are more elements.
15421542
/// assert_eq!(iter.next(), Some(&3));
1543+
///
1544+
/// // The returned index depends on iterator state
1545+
/// assert_eq!(iter.position(|&x| x == 4), Some(0));
1546+
///
15431547
/// ```
15441548
#[inline]
15451549
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)