mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Expand docs on Peekable::peek_mut
This commit is contained in:
parent
774bce7f5e
commit
08ec201c72
@ -230,20 +230,24 @@ impl<I: Iterator> Peekable<I> {
|
|||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
|
/// Basic usage:
|
||||||
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(peekable_peek_mut)]
|
/// #![feature(peekable_peek_mut)]
|
||||||
/// let mut iter = [1, 2, 3].iter().peekable();
|
/// let mut iter = [1, 2, 3].iter().peekable();
|
||||||
///
|
///
|
||||||
|
/// // Like with `peek()`, we can see into the future without advancing the iterator.
|
||||||
|
/// assert_eq!(iter.peek_mut(), Some(&mut &1));
|
||||||
/// assert_eq!(iter.peek_mut(), Some(&mut &1));
|
/// assert_eq!(iter.peek_mut(), Some(&mut &1));
|
||||||
/// assert_eq!(iter.next(), Some(&1));
|
/// assert_eq!(iter.next(), Some(&1));
|
||||||
///
|
///
|
||||||
/// // Peek into the iterator and modify the value which will be returned next
|
/// // Peek into the iterator and set the value behind the mutable reference.
|
||||||
/// if let Some(mut p) = iter.peek_mut() {
|
/// if let Some(p) = iter.peek_mut() {
|
||||||
/// if *p == &2 {
|
/// assert_eq!(*p, &2);
|
||||||
/// *p = &5;
|
/// *p = &5;
|
||||||
/// }
|
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
|
/// // The value we put in reappears as the iterator continues.
|
||||||
/// assert_eq!(iter.collect::<Vec<_>>(), vec![&5, &3]);
|
/// assert_eq!(iter.collect::<Vec<_>>(), vec![&5, &3]);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
|
Loading…
Reference in New Issue
Block a user