mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Rollup merge of #134579 - hkBst:patch-6, r=jhpratt
Improve prose around into_slice example of IterMut Having a part without modification and one with seems redundant, since `into_slice` is only called for the part without. I have brought the modification into the remaining part, although it perhaps does not add much (or only distracts?).
This commit is contained in:
commit
c682d30337
@ -259,28 +259,21 @@ impl<'a, T> IterMut<'a, T> {
|
|||||||
/// Basic usage:
|
/// Basic usage:
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// // First, we declare a type which has `iter_mut` method to get the `IterMut`
|
/// // First, we need a slice to call the `iter_mut` method on:
|
||||||
/// // struct (`&[usize]` here):
|
|
||||||
/// let mut slice = &mut [1, 2, 3];
|
/// let mut slice = &mut [1, 2, 3];
|
||||||
///
|
///
|
||||||
/// {
|
/// // Then we call `iter_mut` on the slice to get the `IterMut` struct:
|
||||||
/// // Then, we get the iterator:
|
/// let mut iter = slice.iter_mut();
|
||||||
/// let mut iter = slice.iter_mut();
|
/// // Now, we call the `next` method to remove the first element of the iterator,
|
||||||
/// // We move to next element:
|
/// // unwrap and dereference what we get from `next` and increase its value by 1:
|
||||||
/// iter.next();
|
/// *iter.next().unwrap() += 1;
|
||||||
/// // So if we print what `into_slice` method returns here, we have "[2, 3]":
|
/// // Here the iterator does not contain the first element of the slice any more,
|
||||||
/// println!("{:?}", iter.into_slice());
|
/// // so `into_slice` only returns the last two elements of the slice,
|
||||||
/// }
|
/// // and so this prints "[2, 3]":
|
||||||
///
|
/// println!("{:?}", iter.into_slice());
|
||||||
/// // Now let's modify a value of the slice:
|
/// // The underlying slice still contains three elements, but its first element
|
||||||
/// {
|
/// // was increased by 1, so this prints "[2, 2, 3]":
|
||||||
/// // First we get back the iterator:
|
/// println!("{:?}", slice);
|
||||||
/// let mut iter = slice.iter_mut();
|
|
||||||
/// // We change the value of the first element of the slice returned by the `next` method:
|
|
||||||
/// *iter.next().unwrap() += 1;
|
|
||||||
/// }
|
|
||||||
/// // Now slice is "[2, 2, 3]":
|
|
||||||
/// println!("{slice:?}");
|
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "`self` will be dropped if the result is not used"]
|
#[must_use = "`self` will be dropped if the result is not used"]
|
||||||
#[stable(feature = "iter_to_slice", since = "1.4.0")]
|
#[stable(feature = "iter_to_slice", since = "1.4.0")]
|
||||||
|
Loading…
Reference in New Issue
Block a user