@@ -259,28 +259,21 @@ impl<'a, T> IterMut<'a, T> {
259
259
/// Basic usage:
260
260
///
261
261
/// ```
262
- /// // First, we declare a type which has `iter_mut` method to get the `IterMut`
263
- /// // struct (`&[usize]` here):
262
+ /// // First, we need a slice to call the `iter_mut` method on:
264
263
/// let mut slice = &mut [1, 2, 3];
265
264
///
266
- /// {
267
- /// // Then, we get the iterator:
268
- /// let mut iter = slice.iter_mut();
269
- /// // We move to next element:
270
- /// iter.next();
271
- /// // So if we print what `into_slice` method returns here, we have "[2, 3]":
272
- /// println!("{:?}", iter.into_slice());
273
- /// }
274
- ///
275
- /// // Now let's modify a value of the slice:
276
- /// {
277
- /// // First we get back the iterator:
278
- /// let mut iter = slice.iter_mut();
279
- /// // We change the value of the first element of the slice returned by the `next` method:
280
- /// *iter.next().unwrap() += 1;
281
- /// }
282
- /// // Now slice is "[2, 2, 3]":
283
- /// println!("{slice:?}");
265
+ /// // Then we call `iter_mut` on the slice to get the `IterMut` struct:
266
+ /// let mut iter = slice.iter_mut();
267
+ /// // Now, we call the `next` method to remove the first element of the iterator,
268
+ /// // unwrap and dereference what we get from `next` and increase its value by 1:
269
+ /// *iter.next().unwrap() += 1;
270
+ /// // Here the iterator does not contain the first element of the slice any more,
271
+ /// // so `into_slice` only returns the last two elements of the slice,
272
+ /// // and so this prints "[2, 3]":
273
+ /// println!("{:?}", iter.into_slice());
274
+ /// // The underlying slice still contains three elements, but its first element
275
+ /// // was increased by 1, so this prints "[2, 2, 3]":
276
+ /// println!("{:?}", slice);
284
277
/// ```
285
278
#[ must_use = "`self` will be dropped if the result is not used" ]
286
279
#[ stable( feature = "iter_to_slice" , since = "1.4.0" ) ]
0 commit comments