Rollup merge of #72720 - poliorcetics:clarify-take-doc, r=joshtriplett

Clarify the documentation of `take`

This PR addresses the concerns of #61222, adding an example for the behaviour of `Iterator::take` when there are less than `n` elements.
This commit is contained in:
Yuki Okushi 2020-05-29 15:07:11 +09:00 committed by GitHub
commit fb506af138
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 0 deletions

View File

@ -1180,6 +1180,17 @@ pub trait Iterator {
/// assert_eq!(iter.next(), Some(2));
/// assert_eq!(iter.next(), None);
/// ```
///
/// If less than `n` elements are available,
/// `take` will limit itself to the size of the underlying iterator:
///
/// ```
/// let v = vec![1, 2];
/// let mut iter = v.into_iter().take(5);
/// assert_eq!(iter.next(), Some(1));
/// assert_eq!(iter.next(), Some(2));
/// assert_eq!(iter.next(), None);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
fn take(self, n: usize) -> Take<Self>