@@ -46,13 +46,19 @@ impl<'a, T> IntoIterator for &'a mut [T] {
46
46
/// Basic usage:
47
47
///
48
48
/// ```
49
- /// // First, we declare a type which has `iter` method to get the `Iter` struct (`&[usize]` here) :
49
+ /// // First, we need a slice to call the `iter` method on :
50
50
/// let slice = &[1, 2, 3];
51
51
///
52
- /// // Then, we iterate over it:
52
+ /// // Then we call `iter` on the slice to get the `Iter` struct,
53
+ /// // and iterate over it:
53
54
/// for element in slice.iter() {
54
55
/// println!("{element}");
55
56
/// }
57
+ ///
58
+ /// // This for loop actually already works without calling `iter`:
59
+ /// for element in slice {
60
+ /// println!("{element}");
61
+ /// }
56
62
/// ```
57
63
///
58
64
/// [`iter`]: slice::iter
@@ -166,11 +172,11 @@ impl<T> AsRef<[T]> for Iter<'_, T> {
166
172
/// Basic usage:
167
173
///
168
174
/// ```
169
- /// // First, we declare a type which has `iter_mut` method to get the `IterMut`
170
- /// // struct (`&[usize]` here):
171
- /// let mut slice = &mut [1, 2, 3];
175
+ /// // First, we need a slice to call the `iter_mut` method on:
176
+ /// let slice = &mut [1, 2, 3];
172
177
///
173
- /// // Then, we iterate over it and increment each element value:
178
+ /// // Then we call `iter_mut` on the slice to get the `IterMut` struct,
179
+ /// // iterate over it and increment each element value:
174
180
/// for element in slice.iter_mut() {
175
181
/// *element += 1;
176
182
/// }
0 commit comments