Skip to content

Commit eef10e6

Browse files
authored
Rollup merge of rust-lang#33265 - tshepang:peek, r=steveklabnik
doc: some `peek` improvements
2 parents 155f0ec + db26b3f commit eef10e6

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/libcore/iter/mod.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,17 +1198,15 @@ impl<I: ExactSizeIterator> ExactSizeIterator for Peekable<I> {}
11981198
impl<I: Iterator> Peekable<I> {
11991199
/// Returns a reference to the next() value without advancing the iterator.
12001200
///
1201-
/// The `peek()` method will return the value that a call to [`next()`] would
1202-
/// return, but does not advance the iterator. Like [`next()`], if there is
1203-
/// a value, it's wrapped in a `Some(T)`, but if the iterator is over, it
1204-
/// will return `None`.
1201+
/// Like [`next()`], if there is a value, it is wrapped in a `Some(T)`.
1202+
/// But if the iteration is over, `None` is returned.
12051203
///
12061204
/// [`next()`]: trait.Iterator.html#tymethod.next
12071205
///
1208-
/// Because `peek()` returns reference, and many iterators iterate over
1209-
/// references, this leads to a possibly confusing situation where the
1206+
/// Because `peek()` returns a reference, and many iterators iterate over
1207+
/// references, there can be a possibly confusing situation where the
12101208
/// return value is a double reference. You can see this effect in the
1211-
/// examples below, with `&&i32`.
1209+
/// examples below.
12121210
///
12131211
/// # Examples
12141212
///
@@ -1225,13 +1223,13 @@ impl<I: Iterator> Peekable<I> {
12251223
///
12261224
/// assert_eq!(iter.next(), Some(&2));
12271225
///
1228-
/// // we can peek() multiple times, the iterator won't advance
1226+
/// // The iterator does not advance even if we `peek` multiple times
12291227
/// assert_eq!(iter.peek(), Some(&&3));
12301228
/// assert_eq!(iter.peek(), Some(&&3));
12311229
///
12321230
/// assert_eq!(iter.next(), Some(&3));
12331231
///
1234-
/// // after the iterator is finished, so is peek()
1232+
/// // After the iterator is finished, so is `peek()`
12351233
/// assert_eq!(iter.peek(), None);
12361234
/// assert_eq!(iter.next(), None);
12371235
/// ```
@@ -1263,10 +1261,10 @@ impl<I: Iterator> Peekable<I> {
12631261
///
12641262
/// let mut iter = xs.iter().peekable();
12651263
///
1266-
/// // there are still elements to iterate over
1264+
/// // There are still elements to iterate over
12671265
/// assert_eq!(iter.is_empty(), false);
12681266
///
1269-
/// // let's consume the iterator
1267+
/// // Let's consume the iterator
12701268
/// iter.next();
12711269
/// iter.next();
12721270
/// iter.next();

0 commit comments

Comments
 (0)