Skip to content

Commit bf0193c

Browse files
wmstackbluebear94
andauthored
Apply suggestions from code review
Improve documentation for `PeekableIterator` to reflect the changes in API Co-authored-by: +merlan #flirora <[email protected]>
1 parent 3dd13bc commit bf0193c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

library/core/src/iter/traits/peekable.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
#[unstable(feature = "peekable_iterator", issue = "132973")]
2-
/// Iterators which inherently support `peek()` without needing to be wrapped by a `Peekable`.
2+
/// Iterators which inherently support peeking without needing to be wrapped by a `Peekable`.
33
pub trait PeekableIterator: Iterator {
4-
/// executes the closure with an Option containing `None` if the iterator is exhausted or Some(&Self::Item)
4+
/// Executes the closure with a reference to the `next()` value without advancing the iterator.
55
fn peek_with<T>(&mut self, func: impl for<'a> FnOnce(Option<&'a Self::Item>) -> T) -> T;
66

7-
/// executes the closure on the next element without advancing the iterator, or returns None if the iterator is exhausted.
7+
/// Executes the closure on the `next()` element without advancing the iterator, or returns `None` if the iterator is exhausted.
88
fn peek_map<T>(&mut self, func: impl for<'a> FnOnce(&'a Self::Item) -> T) -> Option<T> {
99
self.peek_with(|x| x.map(|y| func(y)))
1010
}
1111

12-
/// returns the `next()` element if a predicate holds true
12+
/// Returns the `next()` element if the given predicate holds true.
1313
fn next_if(&mut self, func: impl FnOnce(&Self::Item) -> bool) -> Option<Self::Item> {
1414
self.peek_map(func).and_then(|_| self.next())
1515
}
1616

17-
/// move forward and return the `next()` item if it is equal to the expected value
17+
/// Moves forward and return the `next()` item if it is equal to the expected value.
1818
fn next_if_eq<T>(&mut self, expected: &T) -> Option<Self::Item>
1919
where
2020
Self::Item: PartialEq<T>,

0 commit comments

Comments
 (0)