about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJacob Pratt <jacob@jhpratt.dev>2024-12-21 01:18:41 -0500
committerGitHub <noreply@github.com>2024-12-21 01:18:41 -0500
commit91320f6eb897e474d12dc3da7c973dd09758f2ec (patch)
treed5f56f0036a0eac9b8b45041226d6f564a96f482
parentba4f4f6a4f833a2d216c01496c6adb66da7d87e9 (diff)
parent3cfe66ab6537b0ea3badcd02b8648a8d8a29baa3 (diff)
downloadrust-91320f6eb897e474d12dc3da7c973dd09758f2ec.tar.gz
rust-91320f6eb897e474d12dc3da7c973dd09758f2ec.zip
Rollup merge of #134577 - hkBst:patch-5, r=jhpratt
Improve prose around `as_slice` example of Iter
-rw-r--r--library/core/src/slice/iter.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/library/core/src/slice/iter.rs b/library/core/src/slice/iter.rs
index e076fbe517f..d3e79f5ff5a 100644
--- a/library/core/src/slice/iter.rs
+++ b/library/core/src/slice/iter.rs
@@ -115,19 +115,25 @@ impl<'a, T> Iter<'a, T> {
     /// Basic usage:
     ///
     /// ```
-    /// // First, we declare a type which has the `iter` method to get the `Iter`
+    /// // First, we need a slice to call the `iter` method on:
     /// // struct (`&[usize]` here):
     /// let slice = &[1, 2, 3];
     ///
-    /// // Then, we get the iterator:
+    /// // Then we call `iter` on the slice to get the `Iter` struct:
     /// let mut iter = slice.iter();
-    /// // So if we print what `as_slice` method returns here, we have "[1, 2, 3]":
+    /// // Here `as_slice` still returns the whole slice, so this prints "[1, 2, 3]":
     /// println!("{:?}", iter.as_slice());
     ///
-    /// // Next, we move to the second element of the slice:
+    /// // Now, we call the `next` method to remove the first element of the iterator:
     /// iter.next();
-    /// // Now `as_slice` returns "[2, 3]":
+    /// // Here the iterator does not contain the first element of the slice any more,
+    /// // so `as_slice` only returns the last two elements of the slice,
+    /// // and so this prints "[2, 3]":
     /// println!("{:?}", iter.as_slice());
+    ///
+    /// // The underlying slice has not been modified and still contains three elements,
+    /// // so this prints "[1, 2, 3]":
+    /// println!("{:?}", slice);
     /// ```
     #[must_use]
     #[stable(feature = "iter_to_slice", since = "1.4.0")]