Skip to content
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

Clarify non-exact length in the Iterator::take documentation #83272

Merged
merged 1 commit into from
Mar 22, 2021
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
15 changes: 13 additions & 2 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,11 @@ pub trait Iterator {

/// Creates an iterator that skips the first `n` elements.
///
/// After they have been consumed, the rest of the elements are yielded.
/// `skip(n)` skips elements until `n` elements are skipped or the end of the
/// iterator is reached (whichever happens first). After that, all the remaining
/// elements are yielded. In particular, if the original iterator is too short,
/// then the returned iterator is empty.
///
/// Rather than overriding this method directly, instead override the `nth` method.
///
/// # Examples
Expand All @@ -1252,7 +1256,14 @@ pub trait Iterator {
Skip::new(self, n)
}

/// Creates an iterator that yields its first `n` elements.
/// Creates an iterator that yields the first `n` elements, or fewer
/// if the underlying iterator ends sooner.
///
/// `take(n)` yields elements until `n` elements are yielded or the end of
/// the iterator is reached (whichever happens first).
/// The returned iterator is a prefix of length `n` if the original iterator
/// contains at least `n` elements, otherwise it contains all of the
/// (fewer than `n`) elements of the original iterator.
///
/// # Examples
///
Expand Down