Rollup merge of #134576 - hkBst:patch-4, r=jhpratt
Improve prose around basic examples of Iter and IterMut
This commit is contained in:
commit
ba4f4f6a4f
1 changed files with 12 additions and 6 deletions
|
@ -46,13 +46,19 @@ impl<'a, T> IntoIterator for &'a mut [T] {
|
|||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// // First, we declare a type which has `iter` method to get the `Iter` struct (`&[usize]` here):
|
||||
/// // First, we need a slice to call the `iter` method on:
|
||||
/// let slice = &[1, 2, 3];
|
||||
///
|
||||
/// // Then, we iterate over it:
|
||||
/// // Then we call `iter` on the slice to get the `Iter` struct,
|
||||
/// // and iterate over it:
|
||||
/// for element in slice.iter() {
|
||||
/// println!("{element}");
|
||||
/// }
|
||||
///
|
||||
/// // This for loop actually already works without calling `iter`:
|
||||
/// for element in slice {
|
||||
/// println!("{element}");
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// [`iter`]: slice::iter
|
||||
|
@ -166,11 +172,11 @@ impl<T> AsRef<[T]> for Iter<'_, T> {
|
|||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// // First, we declare a type which has `iter_mut` method to get the `IterMut`
|
||||
/// // struct (`&[usize]` here):
|
||||
/// let mut slice = &mut [1, 2, 3];
|
||||
/// // First, we need a slice to call the `iter_mut` method on:
|
||||
/// let slice = &mut [1, 2, 3];
|
||||
///
|
||||
/// // Then, we iterate over it and increment each element value:
|
||||
/// // Then we call `iter_mut` on the slice to get the `IterMut` struct,
|
||||
/// // iterate over it and increment each element value:
|
||||
/// for element in slice.iter_mut() {
|
||||
/// *element += 1;
|
||||
/// }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue