Skip to content

Commit db26b3f

Browse files
committed
doc: some peek improvements
1 parent c049541 commit db26b3f

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/libcore/iter/mod.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -1048,17 +1048,15 @@ impl<I: ExactSizeIterator> ExactSizeIterator for Peekable<I> {}
10481048
impl<I: Iterator> Peekable<I> {
10491049
/// Returns a reference to the next() value without advancing the iterator.
10501050
///
1051-
/// The `peek()` method will return the value that a call to [`next()`] would
1052-
/// return, but does not advance the iterator. Like [`next()`], if there is
1053-
/// a value, it's wrapped in a `Some(T)`, but if the iterator is over, it
1054-
/// will return `None`.
1051+
/// Like [`next()`], if there is a value, it is wrapped in a `Some(T)`.
1052+
/// But if the iteration is over, `None` is returned.
10551053
///
10561054
/// [`next()`]: trait.Iterator.html#tymethod.next
10571055
///
1058-
/// Because `peek()` returns reference, and many iterators iterate over
1059-
/// references, this leads to a possibly confusing situation where the
1056+
/// Because `peek()` returns a reference, and many iterators iterate over
1057+
/// references, there can be a possibly confusing situation where the
10601058
/// return value is a double reference. You can see this effect in the
1061-
/// examples below, with `&&i32`.
1059+
/// examples below.
10621060
///
10631061
/// # Examples
10641062
///
@@ -1075,13 +1073,13 @@ impl<I: Iterator> Peekable<I> {
10751073
///
10761074
/// assert_eq!(iter.next(), Some(&2));
10771075
///
1078-
/// // we can peek() multiple times, the iterator won't advance
1076+
/// // The iterator does not advance even if we `peek` multiple times
10791077
/// assert_eq!(iter.peek(), Some(&&3));
10801078
/// assert_eq!(iter.peek(), Some(&&3));
10811079
///
10821080
/// assert_eq!(iter.next(), Some(&3));
10831081
///
1084-
/// // after the iterator is finished, so is peek()
1082+
/// // After the iterator is finished, so is `peek()`
10851083
/// assert_eq!(iter.peek(), None);
10861084
/// assert_eq!(iter.next(), None);
10871085
/// ```
@@ -1113,10 +1111,10 @@ impl<I: Iterator> Peekable<I> {
11131111
///
11141112
/// let mut iter = xs.iter().peekable();
11151113
///
1116-
/// // there are still elements to iterate over
1114+
/// // There are still elements to iterate over
11171115
/// assert_eq!(iter.is_empty(), false);
11181116
///
1119-
/// // let's consume the iterator
1117+
/// // Let's consume the iterator
11201118
/// iter.next();
11211119
/// iter.next();
11221120
/// iter.next();

0 commit comments

Comments
 (0)