]> git.lizzy.rs Git - rust.git/commitdiff
Clarify Iterator::position doc
authorSebastian Hahn <sebastian@torproject.org>
Tue, 11 Apr 2017 12:51:56 +0000 (14:51 +0200)
committerSebastian Hahn <sebastian@torproject.org>
Tue, 11 Apr 2017 17:39:58 +0000 (19:39 +0200)
Extend the example a little bit to show behaviour better.

src/libcore/iter/iterator.rs

index 618edf48abd04370a43073368ac33bedb3129754..8bf641e37fe467c2120defd6b1a90afc79b0674c 100644 (file)
@@ -1532,14 +1532,18 @@ fn find<P>(&mut self, mut predicate: P) -> Option<Self::Item> where
     /// 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")]