diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-04-01 11:28:34 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-04-01 13:29:42 -0700 |
| commit | e98dce3e00a7b6bfd264418ef993bbf9cdb1f0b6 (patch) | |
| tree | 1569b4aa8d412df9c49904b8bddeb44d8d4ecef2 /src/libcollections/slice.rs | |
| parent | d528aa9960cb9b937d8ef6c09905a6a8076d5f3a (diff) | |
| download | rust-e98dce3e00a7b6bfd264418ef993bbf9cdb1f0b6.tar.gz rust-e98dce3e00a7b6bfd264418ef993bbf9cdb1f0b6.zip | |
std: Changing the meaning of the count to splitn
This commit is an implementation of [RFC 979][rfc] which changes the meaning of the count parameter to the `splitn` function on strings and slices. The parameter now means the number of items that are returned from the iterator, not the number of splits that are made. [rfc]: https://github.com/rust-lang/rfcs/pull/979 Closes #23911 [breaking-change]
Diffstat (limited to 'src/libcollections/slice.rs')
| -rw-r--r-- | src/libcollections/slice.rs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 4599aff000d..d35173cbebf 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -328,9 +328,12 @@ impl<T> [T] { } /// Returns an iterator over subslices separated by elements that match - /// `pred`, limited to splitting at most `n` times. The matched element is + /// `pred`, limited to returning at most `n` items. The matched element is /// not contained in the subslices. /// + /// The last element returned, if any, will contain the remainder of the + /// slice. + /// /// # Examples /// /// Print the slice split once by numbers divisible by 3 (i.e. `[10, 40]`, @@ -338,7 +341,7 @@ impl<T> [T] { /// /// ``` /// let v = [10, 40, 30, 20, 60, 50]; - /// for group in v.splitn(1, |num| *num % 3 == 0) { + /// for group in v.splitn(2, |num| *num % 3 == 0) { /// println!("{:?}", group); /// } /// ``` @@ -349,10 +352,13 @@ impl<T> [T] { } /// Returns an iterator over subslices separated by elements that match - /// `pred` limited to splitting at most `n` times. This starts at the end of + /// `pred` limited to returning at most `n` items. This starts at the end of /// the slice and works backwards. The matched element is not contained in /// the subslices. /// + /// The last element returned, if any, will contain the remainder of the + /// slice. + /// /// # Examples /// /// Print the slice split once, starting from the end, by numbers divisible @@ -360,7 +366,7 @@ impl<T> [T] { /// /// ``` /// let v = [10, 40, 30, 20, 60, 50]; - /// for group in v.rsplitn(1, |num| *num % 3 == 0) { + /// for group in v.rsplitn(2, |num| *num % 3 == 0) { /// println!("{:?}", group); /// } /// ``` @@ -626,8 +632,11 @@ impl<T> [T] { } /// Returns an iterator over subslices separated by elements that match - /// `pred`, limited to splitting at most `n` times. The matched element is + /// `pred`, limited to returning at most `n` items. The matched element is /// not contained in the subslices. + /// + /// The last element returned, if any, will contain the remainder of the + /// slice. #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn splitn_mut<F>(&mut self, n: usize, pred: F) -> SplitNMut<T, F> @@ -636,9 +645,12 @@ impl<T> [T] { } /// Returns an iterator over subslices separated by elements that match - /// `pred` limited to splitting at most `n` times. This starts at the end of + /// `pred` limited to returning at most `n` items. This starts at the end of /// the slice and works backwards. The matched element is not contained in /// the subslices. + /// + /// The last element returned, if any, will contain the remainder of the + /// slice. #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn rsplitn_mut<F>(&mut self, n: usize, pred: F) -> RSplitNMut<T, F> |
