Skip to content

Commit

Permalink
Improve prose around as_slice example of Iter
Browse files Browse the repository at this point in the history
  • Loading branch information
hkBst authored and gitbot committed Feb 20, 2025
1 parent 5140d3c commit 2e36c44
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions core/src/slice/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,25 @@ impl<'a, T> Iter<'a, T> {
/// Basic usage:
///
/// ```
/// // First, we declare a type which has the `iter` method to get the `Iter`
/// // First, we need a slice to call the `iter` method on:
/// // struct (`&[usize]` here):
/// let slice = &[1, 2, 3];
///
/// // Then, we get the iterator:
/// // Then we call `iter` on the slice to get the `Iter` struct:
/// let mut iter = slice.iter();
/// // So if we print what `as_slice` method returns here, we have "[1, 2, 3]":
/// // Here `as_slice` still returns the whole slice, so this prints "[1, 2, 3]":
/// println!("{:?}", iter.as_slice());
///
/// // Next, we move to the second element of the slice:
/// // Now, we call the `next` method to remove the first element of the iterator:
/// iter.next();
/// // Now `as_slice` returns "[2, 3]":
/// // Here the iterator does not contain the first element of the slice any more,
/// // so `as_slice` only returns the last two elements of the slice,
/// // and so this prints "[2, 3]":
/// println!("{:?}", iter.as_slice());
///
/// // The underlying slice has not been modified and still contains three elements,
/// // so this prints "[1, 2, 3]":
/// println!("{:?}", slice);
/// ```
#[must_use]
#[stable(feature = "iter_to_slice", since = "1.4.0")]
Expand Down

0 comments on commit 2e36c44

Please sign in to comment.