diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2021-03-22 15:21:26 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-22 15:21:26 +0100 |
| commit | f441c2a9a098cdabfc6c3d4505f0b6c0ef318520 (patch) | |
| tree | 2c2bbd5f8fb1e7638a9f0d398e595fa2d4e795a2 | |
| parent | 83faac9da458d8f451611b4587e0c807d1db4af5 (diff) | |
| parent | 6cfdc385a1e3e9dd624ce87c75f25f1bb16118a1 (diff) | |
| download | rust-f441c2a9a098cdabfc6c3d4505f0b6c0ef318520.tar.gz rust-f441c2a9a098cdabfc6c3d4505f0b6c0ef318520.zip | |
Rollup merge of #83272 - kornelski:takedocs, r=dtolnay
Clarify non-exact length in the Iterator::take documentation There's an example which demonstrates incomplete length case, but it'd be best to explain it right from the start.
| -rw-r--r-- | library/core/src/iter/traits/iterator.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index a07750f4ad1..46e1a3a4aa2 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -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 @@ -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 /// |
