File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
library/core/src/iter/adapters Expand file tree Collapse file tree 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> {
230230 ///
231231 /// # Examples
232232 ///
233+ /// Basic usage:
234+ ///
233235 /// ```
234236 /// #![feature(peekable_peek_mut)]
235237 /// let mut iter = [1, 2, 3].iter().peekable();
236238 ///
239+ /// // Like with `peek()`, we can see into the future without advancing the iterator.
240+ /// assert_eq!(iter.peek_mut(), Some(&mut &1));
237241 /// assert_eq!(iter.peek_mut(), Some(&mut &1));
238242 /// assert_eq!(iter.next(), Some(&1));
239243 ///
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;
245248 /// }
246249 ///
250+ /// // The value we put in reappears as the iterator continues.
247251 /// assert_eq!(iter.collect::<Vec<_>>(), vec![&5, &3]);
248252 /// ```
249253 #[ inline]
You can’t perform that action at this time.
0 commit comments