about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThe 8472 <git@infinite-source.de>2022-06-30 19:45:36 +0200
committerThe 8472 <git@infinite-source.de>2022-06-30 19:45:36 +0200
commit3fcf84a68e2d75035e3ca867dc925583aee0cbb0 (patch)
treef6621f58c345e5f4be6e5123ea1c680f368f4869
parent7425fb293f510a6f138e82a963a3bc599a5b9e1c (diff)
downloadrust-3fcf84a68e2d75035e3ca867dc925583aee0cbb0.tar.gz
rust-3fcf84a68e2d75035e3ca867dc925583aee0cbb0.zip
clarify that ExactSizeIterator::len returns the remaining length
-rw-r--r--library/core/src/iter/traits/exact_size.rs12
-rw-r--r--library/core/src/iter/traits/iterator.rs4
2 files changed, 11 insertions, 5 deletions
diff --git a/library/core/src/iter/traits/exact_size.rs b/library/core/src/iter/traits/exact_size.rs
index a476799b70d..1757e37ec0e 100644
--- a/library/core/src/iter/traits/exact_size.rs
+++ b/library/core/src/iter/traits/exact_size.rs
@@ -66,13 +66,15 @@
 ///
 /// // And now we can use it!
 ///
-/// let counter = Counter::new();
+/// let mut counter = Counter::new();
 ///
 /// assert_eq!(5, counter.len());
+/// let _ = counter.next();
+/// assert_eq!(4, counter.len());
 /// ```
 #[stable(feature = "rust1", since = "1.0.0")]
 pub trait ExactSizeIterator: Iterator {
-    /// Returns the exact length of the iterator.
+    /// Returns the exact remaining length of the iterator.
     ///
     /// The implementation ensures that the iterator will return exactly `len()`
     /// more times a [`Some(T)`] value, before returning [`None`].
@@ -93,9 +95,11 @@ pub trait ExactSizeIterator: Iterator {
     ///
     /// ```
     /// // a finite range knows exactly how many times it will iterate
-    /// let five = 0..5;
+    /// let mut range = 0..5;
     ///
-    /// assert_eq!(5, five.len());
+    /// assert_eq!(5, range.len());
+    /// let _ = range.next();
+    /// assert_eq!(4, range.len());
     /// ```
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs
index 326b98ec947..275412b57b5 100644
--- a/library/core/src/iter/traits/iterator.rs
+++ b/library/core/src/iter/traits/iterator.rs
@@ -177,9 +177,11 @@ pub trait Iterator {
     ///
     /// ```
     /// let a = [1, 2, 3];
-    /// let iter = a.iter();
+    /// let mut iter = a.iter();
     ///
     /// assert_eq!((3, Some(3)), iter.size_hint());
+    /// let _ = iter.next();
+    /// assert_eq!((2, Some(2)), iter.size_hint());
     /// ```
     ///
     /// A more complex example: