diff options
| author | Alexis Bourget <alexis.bourget@gmail.com> | 2020-05-29 03:29:01 +0200 |
|---|---|---|
| committer | Alexis Bourget <alexis.bourget@gmail.com> | 2020-05-29 03:29:01 +0200 |
| commit | 85f4f1c95a3eceae1e69a0fbf995cb7e7737e104 (patch) | |
| tree | ab095fff3e7615a8c0694993246552cfed71a8e3 /src/libcore | |
| parent | 45127211566c53bac386b66909a830649182ab7a (diff) | |
| download | rust-85f4f1c95a3eceae1e69a0fbf995cb7e7737e104.tar.gz rust-85f4f1c95a3eceae1e69a0fbf995cb7e7737e104.zip | |
Clarify the documentation of take
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/iter/traits/iterator.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/libcore/iter/traits/iterator.rs b/src/libcore/iter/traits/iterator.rs index 1c3d95cbb8c..7f081f732fd 100644 --- a/src/libcore/iter/traits/iterator.rs +++ b/src/libcore/iter/traits/iterator.rs @@ -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> |
