about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-07-01 06:05:56 +0200
committerGitHub <noreply@github.com>2022-07-01 06:05:56 +0200
commit734f21c9e20fbeea33bf1ab5da9bba1cce39b2a0 (patch)
treedae5620c0b6a60e7ea1283acc158df1aac9e83c3
parente59693a0460fa1642fe650ff298c6b9479a60f0d (diff)
parent3fcf84a68e2d75035e3ca867dc925583aee0cbb0 (diff)
downloadrust-734f21c9e20fbeea33bf1ab5da9bba1cce39b2a0.tar.gz
rust-734f21c9e20fbeea33bf1ab5da9bba1cce39b2a0.zip
Rollup merge of #98729 - the8472:exactsize-docs, r=thomcc
clarify that ExactSizeIterator::len returns the remaining length

fixes #98721
-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: