File tree 1 file changed +9
-5
lines changed
library/core/src/iter/adapters
1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -230,20 +230,24 @@ impl<I: Iterator> Peekable<I> {
230
230
///
231
231
/// # Examples
232
232
///
233
+ /// Basic usage:
234
+ ///
233
235
/// ```
234
236
/// #![feature(peekable_peek_mut)]
235
237
/// let mut iter = [1, 2, 3].iter().peekable();
236
238
///
239
+ /// // Like with `peek()`, we can see into the future without advancing the iterator.
240
+ /// assert_eq!(iter.peek_mut(), Some(&mut &1));
237
241
/// assert_eq!(iter.peek_mut(), Some(&mut &1));
238
242
/// assert_eq!(iter.next(), Some(&1));
239
243
///
240
- /// // Peek into the iterator and modify the value which will be returned next
241
- /// if let Some(mut p) = iter.peek_mut() {
242
- /// if *p == &2 {
243
- /// *p = &5;
244
- /// }
244
+ /// // Peek into the iterator and set the value behind the mutable reference.
245
+ /// if let Some(p) = iter.peek_mut() {
246
+ /// assert_eq!(*p, &2);
247
+ /// *p = &5;
245
248
/// }
246
249
///
250
+ /// // The value we put in reappears as the iterator continues.
247
251
/// assert_eq!(iter.collect::<Vec<_>>(), vec![&5, &3]);
248
252
/// ```
249
253
#[ inline]
You can’t perform that action at this time.
0 commit comments