Skip to content

Commit

Permalink
Rollup merge of #72720 - poliorcetics:clarify-take-doc, r=joshtriplett
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JohnTitor authored May 29, 2020
2 parents 5207428 + 85f4f1c commit fb506af
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/libcore/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit fb506af

Please sign in to comment.