Skip to content

Commit 78c9a96

Browse files
authored
Unrolled build for rust-lang#134577
Rollup merge of rust-lang#134577 - hkBst:patch-5, r=jhpratt Improve prose around `as_slice` example of Iter
2 parents 73c278f + 3cfe66a commit 78c9a96

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

library/core/src/slice/iter.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,25 @@ impl<'a, T> Iter<'a, T> {
109109
/// Basic usage:
110110
///
111111
/// ```
112-
/// // First, we declare a type which has the `iter` method to get the `Iter`
112+
/// // First, we need a slice to call the `iter` method on:
113113
/// // struct (`&[usize]` here):
114114
/// let slice = &[1, 2, 3];
115115
///
116-
/// // Then, we get the iterator:
116+
/// // Then we call `iter` on the slice to get the `Iter` struct:
117117
/// let mut iter = slice.iter();
118-
/// // So if we print what `as_slice` method returns here, we have "[1, 2, 3]":
118+
/// // Here `as_slice` still returns the whole slice, so this prints "[1, 2, 3]":
119119
/// println!("{:?}", iter.as_slice());
120120
///
121-
/// // Next, we move to the second element of the slice:
121+
/// // Now, we call the `next` method to remove the first element of the iterator:
122122
/// iter.next();
123-
/// // Now `as_slice` returns "[2, 3]":
123+
/// // Here the iterator does not contain the first element of the slice any more,
124+
/// // so `as_slice` only returns the last two elements of the slice,
125+
/// // and so this prints "[2, 3]":
124126
/// println!("{:?}", iter.as_slice());
127+
///
128+
/// // The underlying slice has not been modified and still contains three elements,
129+
/// // so this prints "[1, 2, 3]":
130+
/// println!("{:?}", slice);
125131
/// ```
126132
#[must_use]
127133
#[stable(feature = "iter_to_slice", since = "1.4.0")]

0 commit comments

Comments
 (0)