1
Fork 0

Rollup merge of #134576 - hkBst:patch-4, r=jhpratt

Improve prose around basic examples of Iter and IterMut
This commit is contained in:
Jacob Pratt 2024-12-21 01:18:41 -05:00 committed by GitHub
commit ba4f4f6a4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;
/// }