about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-04-11 18:36:16 -0400
committerGitHub <noreply@github.com>2017-04-11 18:36:16 -0400
commit3ebeaf6d5c951ad622b2b8fc80c2305b17d488b0 (patch)
tree52b1ed1da899521e6002de7c38e708cc508d13ba
parent828ed96377ff89051ff537afff74f768e6eea3c5 (diff)
parent316af6082c8c23615cc54302ee7efa0811bbabe7 (diff)
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
-rw-r--r--src/libcore/iter/iterator.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/libcore/iter/iterator.rs b/src/libcore/iter/iterator.rs
index 618edf48abd..8bf641e37fe 100644
--- a/src/libcore/iter/iterator.rs
+++ b/src/libcore/iter/iterator.rs
@@ -1532,14 +1532,18 @@ pub trait Iterator {
     /// Stopping at the first `true`:
     ///
     /// ```
-    /// let a = [1, 2, 3];
+    /// let a = [1, 2, 3, 4];
     ///
     /// let mut iter = a.iter();
     ///
-    /// assert_eq!(iter.position(|&x| x == 2), Some(1));
+    /// assert_eq!(iter.position(|&x| x >= 2), Some(1));
     ///
     /// // we can still use `iter`, as there are more elements.
     /// assert_eq!(iter.next(), Some(&3));
+    ///
+    /// // The returned index depends on iterator state
+    /// assert_eq!(iter.position(|&x| x == 4), Some(0));
+    ///
     /// ```
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]