Skip to content

Commit 0c4799d

Browse files
hkBstgitbot
authored and
gitbot
committed
Improve prose around as_slice example of Iter
1 parent 07e9d97 commit 0c4799d

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

core/src/slice/iter.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,25 @@ impl<'a, T> Iter<'a, T> {
115115
/// Basic usage:
116116
///
117117
/// ```
118-
/// // First, we declare a type which has the `iter` method to get the `Iter`
118+
/// // First, we need a slice to call the `iter` method on:
119119
/// // struct (`&[usize]` here):
120120
/// let slice = &[1, 2, 3];
121121
///
122-
/// // Then, we get the iterator:
122+
/// // Then we call `iter` on the slice to get the `Iter` struct:
123123
/// let mut iter = slice.iter();
124-
/// // So if we print what `as_slice` method returns here, we have "[1, 2, 3]":
124+
/// // Here `as_slice` still returns the whole slice, so this prints "[1, 2, 3]":
125125
/// println!("{:?}", iter.as_slice());
126126
///
127-
/// // Next, we move to the second element of the slice:
127+
/// // Now, we call the `next` method to remove the first element of the iterator:
128128
/// iter.next();
129-
/// // Now `as_slice` returns "[2, 3]":
129+
/// // Here the iterator does not contain the first element of the slice any more,
130+
/// // so `as_slice` only returns the last two elements of the slice,
131+
/// // and so this prints "[2, 3]":
130132
/// println!("{:?}", iter.as_slice());
133+
///
134+
/// // The underlying slice has not been modified and still contains three elements,
135+
/// // so this prints "[1, 2, 3]":
136+
/// println!("{:?}", slice);
131137
/// ```
132138
#[must_use]
133139
#[stable(feature = "iter_to_slice", since = "1.4.0")]

0 commit comments

Comments
 (0)