Rollup merge of #134577 - hkBst:patch-5, r=jhpratt
Improve prose around `as_slice` example of Iter
This commit is contained in:
commit
91320f6eb8
1 changed files with 11 additions and 5 deletions
|
@ -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")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue