Skip to content

Add a note about side effects for "peekable" iterators #33016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,12 +901,17 @@ pub trait Iterator {
Enumerate { iter: self, count: 0 }
}

/// Creates an iterator which can look at the `next()` element without
/// consuming it.
/// Creates an iterator which can use `peek` to look at the next element of
/// the iterator without consuming it.
///
/// Adds a [`peek()`] method to an iterator. See its documentation for
/// more information.
///
/// Note that the underlying iterator is still advanced when `peek` is
/// called for the first time: In order to retrieve the next element,
/// `next` is called on the underlying iterator, hence any side effects of
/// the `next` method will occur.
///
/// [`peek()`]: struct.Peekable.html#method.peek
///
/// # Examples
Expand Down