From a891f6edfeb4d7b061a215ba160fca0e4804ffd2 Mon Sep 17 00:00:00 2001 From: Clément Renault Date: Thu, 10 Dec 2020 10:16:29 +0100 Subject: Introduce the GroupBy and GroupByMut Iterators --- library/alloc/src/lib.rs | 1 + library/alloc/src/slice.rs | 2 ++ 2 files changed, 3 insertions(+) (limited to 'library/alloc/src') diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 3ac34c9ae28..34102d9c403 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -140,6 +140,7 @@ #![feature(try_trait)] #![feature(type_alias_impl_trait)] #![feature(associated_type_bounds)] +#![feature(slice_group_by)] // Allow testing this library #[cfg(test)] diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 064700fc72c..bfa317ffd73 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -118,6 +118,8 @@ pub use core::slice::{RChunks, RChunksExact, RChunksExactMut, RChunksMut}; pub use core::slice::{RSplit, RSplitMut}; #[stable(feature = "rust1", since = "1.0.0")] pub use core::slice::{RSplitN, RSplitNMut, SplitN, SplitNMut}; +#[unstable(feature = "slice_group_by", issue = "0")] +pub use core::slice::{GroupBy, GroupByMut}; //////////////////////////////////////////////////////////////////////////////// // Basic slice extension methods -- cgit 1.4.1-3-g733a5 From 1b406afe23c17467f43a5c1bd83b4af1d55d08d9 Mon Sep 17 00:00:00 2001 From: Clément Renault Date: Thu, 10 Dec 2020 11:37:40 +0100 Subject: Use none as the issue instead of 0 --- library/alloc/src/slice.rs | 2 +- library/core/src/slice/iter.rs | 18 +++++++++--------- library/core/src/slice/mod.rs | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'library/alloc/src') diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index bfa317ffd73..5f92dfe539f 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -118,7 +118,7 @@ pub use core::slice::{RChunks, RChunksExact, RChunksExactMut, RChunksMut}; pub use core::slice::{RSplit, RSplitMut}; #[stable(feature = "rust1", since = "1.0.0")] pub use core::slice::{RSplitN, RSplitNMut, SplitN, SplitNMut}; -#[unstable(feature = "slice_group_by", issue = "0")] +#[unstable(feature = "slice_group_by", issue = "none")] pub use core::slice::{GroupBy, GroupByMut}; //////////////////////////////////////////////////////////////////////////////// diff --git a/library/core/src/slice/iter.rs b/library/core/src/slice/iter.rs index 90afd00f21d..9053376bdf2 100644 --- a/library/core/src/slice/iter.rs +++ b/library/core/src/slice/iter.rs @@ -2974,21 +2974,21 @@ unsafe impl<'a, T> TrustedRandomAccess for IterMut<'a, T> { /// /// [`group_by`]: ../../std/primitive.slice.html#method.group_by /// [slices]: ../../std/primitive.slice.html -#[unstable(feature = "slice_group_by", issue = "0")] +#[unstable(feature = "slice_group_by", issue = "none")] #[derive(Debug)] // FIXME implement Debug to be more user friendly pub struct GroupBy<'a, T: 'a, P> { slice: &'a [T], predicate: P, } -#[unstable(feature = "slice_group_by", issue = "0")] +#[unstable(feature = "slice_group_by", issue = "none")] impl<'a, T: 'a, P> GroupBy<'a, T, P> { pub(super) fn new(slice: &'a [T], predicate: P) -> Self { GroupBy { slice, predicate } } } -#[unstable(feature = "slice_group_by", issue = "0")] +#[unstable(feature = "slice_group_by", issue = "none")] impl<'a, T: 'a, P> Iterator for GroupBy<'a, T, P> where P: FnMut(&T, &T) -> bool, { @@ -3025,7 +3025,7 @@ where P: FnMut(&T, &T) -> bool, } } -#[unstable(feature = "slice_group_by", issue = "0")] +#[unstable(feature = "slice_group_by", issue = "none")] impl<'a, T: 'a, P> DoubleEndedIterator for GroupBy<'a, T, P> where P: FnMut(&T, &T) -> bool, { @@ -3046,7 +3046,7 @@ where P: FnMut(&T, &T) -> bool, } } -#[unstable(feature = "slice_group_by", issue = "0")] +#[unstable(feature = "slice_group_by", issue = "none")] impl<'a, T: 'a, P> FusedIterator for GroupBy<'a, T, P> where P: FnMut(&T, &T) -> bool, { } @@ -3058,21 +3058,21 @@ where P: FnMut(&T, &T) -> bool, /// /// [`group_by_mut`]: ../../std/primitive.slice.html#method.group_by_mut /// [slices]: ../../std/primitive.slice.html -#[unstable(feature = "slice_group_by", issue = "0")] +#[unstable(feature = "slice_group_by", issue = "none")] #[derive(Debug)] // FIXME implement Debug to be more user friendly pub struct GroupByMut<'a, T: 'a, P> { slice: &'a mut [T], predicate: P, } -#[unstable(feature = "slice_group_by", issue = "0")] +#[unstable(feature = "slice_group_by", issue = "none")] impl<'a, T: 'a, P> GroupByMut<'a, T, P> { pub(super) fn new(slice: &'a mut [T], predicate: P) -> Self { GroupByMut { slice, predicate } } } -#[unstable(feature = "slice_group_by", issue = "0")] +#[unstable(feature = "slice_group_by", issue = "none")] impl<'a, T: 'a, P> Iterator for GroupByMut<'a, T, P> where P: FnMut(&T, &T) -> bool, { @@ -3110,7 +3110,7 @@ where P: FnMut(&T, &T) -> bool, } } -#[unstable(feature = "slice_group_by", issue = "0")] +#[unstable(feature = "slice_group_by", issue = "none")] impl<'a, T: 'a, P> DoubleEndedIterator for GroupByMut<'a, T, P> where P: FnMut(&T, &T) -> bool, { diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 2e304cc5d2e..40f480fa85b 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -1228,7 +1228,7 @@ impl [T] { /// assert_eq!(iter.next(), Some(&[2, 2, 2][..])); /// assert_eq!(iter.next(), None); /// ``` - #[unstable(feature = "slice_group_by", issue = "0")] + #[unstable(feature = "slice_group_by", issue = "none")] #[inline] pub fn group_by(&self, pred: F) -> GroupBy where F: FnMut(&T, &T) -> bool @@ -1257,7 +1257,7 @@ impl [T] { /// assert_eq!(iter.next(), Some(&mut [2, 2, 2][..])); /// assert_eq!(iter.next(), None); /// ``` - #[unstable(feature = "slice_group_by", issue = "0")] + #[unstable(feature = "slice_group_by", issue = "none")] #[inline] pub fn group_by_mut(&mut self, pred: F) -> GroupByMut where F: FnMut(&T, &T) -> bool -- cgit 1.4.1-3-g733a5 From 7952ea5a04aa34dc5441a47f7d4d227193c8fdf6 Mon Sep 17 00:00:00 2001 From: Clément Renault Date: Thu, 10 Dec 2020 19:10:09 +0100 Subject: Fix the fmt issues --- library/alloc/src/slice.rs | 4 ++-- library/core/src/slice/iter.rs | 31 ++++++++++++++----------------- library/core/src/slice/mod.rs | 6 ++++-- 3 files changed, 20 insertions(+), 21 deletions(-) (limited to 'library/alloc/src') diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 5f92dfe539f..72da781da3c 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -110,6 +110,8 @@ pub use core::slice::{Chunks, Windows}; pub use core::slice::{ChunksExact, ChunksExactMut}; #[stable(feature = "rust1", since = "1.0.0")] pub use core::slice::{ChunksMut, Split, SplitMut}; +#[unstable(feature = "slice_group_by", issue = "none")] +pub use core::slice::{GroupBy, GroupByMut}; #[stable(feature = "rust1", since = "1.0.0")] pub use core::slice::{Iter, IterMut}; #[stable(feature = "rchunks", since = "1.31.0")] @@ -118,8 +120,6 @@ pub use core::slice::{RChunks, RChunksExact, RChunksExactMut, RChunksMut}; pub use core::slice::{RSplit, RSplitMut}; #[stable(feature = "rust1", since = "1.0.0")] pub use core::slice::{RSplitN, RSplitNMut, SplitN, SplitNMut}; -#[unstable(feature = "slice_group_by", issue = "none")] -pub use core::slice::{GroupBy, GroupByMut}; //////////////////////////////////////////////////////////////////////////////// // Basic slice extension methods diff --git a/library/core/src/slice/iter.rs b/library/core/src/slice/iter.rs index a10ebacf5fb..423cbd11350 100644 --- a/library/core/src/slice/iter.rs +++ b/library/core/src/slice/iter.rs @@ -2991,7 +2991,8 @@ impl<'a, T: 'a, P> GroupBy<'a, T, P> { #[unstable(feature = "slice_group_by", issue = "none")] impl<'a, T: 'a, P> Iterator for GroupBy<'a, T, P> -where P: FnMut(&T, &T) -> bool, +where + P: FnMut(&T, &T) -> bool, { type Item = &'a [T]; @@ -3013,11 +3014,7 @@ where P: FnMut(&T, &T) -> bool, #[inline] fn size_hint(&self) -> (usize, Option) { - if self.slice.is_empty() { - (0, Some(0)) - } else { - (1, Some(self.slice.len())) - } + if self.slice.is_empty() { (0, Some(0)) } else { (1, Some(self.slice.len())) } } #[inline] @@ -3028,7 +3025,8 @@ where P: FnMut(&T, &T) -> bool, #[unstable(feature = "slice_group_by", issue = "none")] impl<'a, T: 'a, P> DoubleEndedIterator for GroupBy<'a, T, P> -where P: FnMut(&T, &T) -> bool, +where + P: FnMut(&T, &T) -> bool, { #[inline] fn next_back(&mut self) -> Option { @@ -3048,9 +3046,7 @@ where P: FnMut(&T, &T) -> bool, } #[unstable(feature = "slice_group_by", issue = "none")] -impl<'a, T: 'a, P> FusedIterator for GroupBy<'a, T, P> -where P: FnMut(&T, &T) -> bool, -{ } +impl<'a, T: 'a, P> FusedIterator for GroupBy<'a, T, P> where P: FnMut(&T, &T) -> bool {} /// An iterator over slice in (non-overlapping) mutable chunks separated /// by a predicate. @@ -3075,7 +3071,8 @@ impl<'a, T: 'a, P> GroupByMut<'a, T, P> { #[unstable(feature = "slice_group_by", issue = "none")] impl<'a, T: 'a, P> Iterator for GroupByMut<'a, T, P> -where P: FnMut(&T, &T) -> bool, +where + P: FnMut(&T, &T) -> bool, { type Item = &'a mut [T]; @@ -3098,11 +3095,7 @@ where P: FnMut(&T, &T) -> bool, #[inline] fn size_hint(&self) -> (usize, Option) { - if self.slice.is_empty() { - (0, Some(0)) - } else { - (1, Some(self.slice.len())) - } + if self.slice.is_empty() { (0, Some(0)) } else { (1, Some(self.slice.len())) } } #[inline] @@ -3113,7 +3106,8 @@ where P: FnMut(&T, &T) -> bool, #[unstable(feature = "slice_group_by", issue = "none")] impl<'a, T: 'a, P> DoubleEndedIterator for GroupByMut<'a, T, P> -where P: FnMut(&T, &T) -> bool, +where + P: FnMut(&T, &T) -> bool, { #[inline] fn next_back(&mut self) -> Option { @@ -3132,3 +3126,6 @@ where P: FnMut(&T, &T) -> bool, } } } + +#[unstable(feature = "slice_group_by", issue = "none")] +impl<'a, T: 'a, P> FusedIterator for GroupByMut<'a, T, P> where P: FnMut(&T, &T) -> bool {} diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 218cd2c25a2..648cf88b7ef 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -1234,7 +1234,8 @@ impl [T] { #[unstable(feature = "slice_group_by", issue = "none")] #[inline] pub fn group_by(&self, pred: F) -> GroupBy<'_, T, F> - where F: FnMut(&T, &T) -> bool + where + F: FnMut(&T, &T) -> bool, { GroupBy::new(self, pred) } @@ -1263,7 +1264,8 @@ impl [T] { #[unstable(feature = "slice_group_by", issue = "none")] #[inline] pub fn group_by_mut(&mut self, pred: F) -> GroupByMut<'_, T, F> - where F: FnMut(&T, &T) -> bool + where + F: FnMut(&T, &T) -> bool, { GroupByMut::new(self, pred) } -- cgit 1.4.1-3-g733a5 From 8b53be660444d736bb6a6e1c6ba42c8180c968e7 Mon Sep 17 00:00:00 2001 From: Clément Renault Date: Thu, 31 Dec 2020 12:13:03 +0100 Subject: Replace the tracking issue for the slice_group_by feature --- library/alloc/src/slice.rs | 2 +- library/core/src/slice/iter.rs | 24 ++++++++++++------------ library/core/src/slice/mod.rs | 6 +++--- 3 files changed, 16 insertions(+), 16 deletions(-) (limited to 'library/alloc/src') diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 72da781da3c..cb015b94930 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -110,7 +110,7 @@ pub use core::slice::{Chunks, Windows}; pub use core::slice::{ChunksExact, ChunksExactMut}; #[stable(feature = "rust1", since = "1.0.0")] pub use core::slice::{ChunksMut, Split, SplitMut}; -#[unstable(feature = "slice_group_by", issue = "none")] +#[unstable(feature = "slice_group_by", issue = "80552")] pub use core::slice::{GroupBy, GroupByMut}; #[stable(feature = "rust1", since = "1.0.0")] pub use core::slice::{Iter, IterMut}; diff --git a/library/core/src/slice/iter.rs b/library/core/src/slice/iter.rs index 6bb9cf99402..a367b4737db 100644 --- a/library/core/src/slice/iter.rs +++ b/library/core/src/slice/iter.rs @@ -2975,20 +2975,20 @@ unsafe impl<'a, T> TrustedRandomAccess for IterMut<'a, T> { /// /// [`group_by`]: ../../std/primitive.slice.html#method.group_by /// [slices]: ../../std/primitive.slice.html -#[unstable(feature = "slice_group_by", issue = "none")] +#[unstable(feature = "slice_group_by", issue = "80552")] pub struct GroupBy<'a, T: 'a, P> { slice: &'a [T], predicate: P, } -#[unstable(feature = "slice_group_by", issue = "none")] +#[unstable(feature = "slice_group_by", issue = "80552")] impl<'a, T: 'a, P> GroupBy<'a, T, P> { pub(super) fn new(slice: &'a [T], predicate: P) -> Self { GroupBy { slice, predicate } } } -#[unstable(feature = "slice_group_by", issue = "none")] +#[unstable(feature = "slice_group_by", issue = "80552")] impl<'a, T: 'a, P> Iterator for GroupBy<'a, T, P> where P: FnMut(&T, &T) -> bool, @@ -3022,7 +3022,7 @@ where } } -#[unstable(feature = "slice_group_by", issue = "none")] +#[unstable(feature = "slice_group_by", issue = "80552")] impl<'a, T: 'a, P> DoubleEndedIterator for GroupBy<'a, T, P> where P: FnMut(&T, &T) -> bool, @@ -3044,10 +3044,10 @@ where } } -#[unstable(feature = "slice_group_by", issue = "none")] +#[unstable(feature = "slice_group_by", issue = "80552")] impl<'a, T: 'a, P> FusedIterator for GroupBy<'a, T, P> where P: FnMut(&T, &T) -> bool {} -#[unstable(feature = "slice_group_by", issue = "none")] +#[unstable(feature = "slice_group_by", issue = "80552")] impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for GroupBy<'a, T, P> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("GroupBy").field("slice", &self.slice).finish() @@ -3061,20 +3061,20 @@ impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for GroupBy<'a, T, P> { /// /// [`group_by_mut`]: ../../std/primitive.slice.html#method.group_by_mut /// [slices]: ../../std/primitive.slice.html -#[unstable(feature = "slice_group_by", issue = "none")] +#[unstable(feature = "slice_group_by", issue = "80552")] pub struct GroupByMut<'a, T: 'a, P> { slice: &'a mut [T], predicate: P, } -#[unstable(feature = "slice_group_by", issue = "none")] +#[unstable(feature = "slice_group_by", issue = "80552")] impl<'a, T: 'a, P> GroupByMut<'a, T, P> { pub(super) fn new(slice: &'a mut [T], predicate: P) -> Self { GroupByMut { slice, predicate } } } -#[unstable(feature = "slice_group_by", issue = "none")] +#[unstable(feature = "slice_group_by", issue = "80552")] impl<'a, T: 'a, P> Iterator for GroupByMut<'a, T, P> where P: FnMut(&T, &T) -> bool, @@ -3109,7 +3109,7 @@ where } } -#[unstable(feature = "slice_group_by", issue = "none")] +#[unstable(feature = "slice_group_by", issue = "80552")] impl<'a, T: 'a, P> DoubleEndedIterator for GroupByMut<'a, T, P> where P: FnMut(&T, &T) -> bool, @@ -3132,10 +3132,10 @@ where } } -#[unstable(feature = "slice_group_by", issue = "none")] +#[unstable(feature = "slice_group_by", issue = "80552")] impl<'a, T: 'a, P> FusedIterator for GroupByMut<'a, T, P> where P: FnMut(&T, &T) -> bool {} -#[unstable(feature = "slice_group_by", issue = "none")] +#[unstable(feature = "slice_group_by", issue = "80552")] impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for GroupByMut<'a, T, P> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("GroupByMut").field("slice", &self.slice).finish() diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index b4dd057eef0..b1332a3f7bc 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -57,7 +57,7 @@ pub use iter::{ArrayChunks, ArrayChunksMut}; #[unstable(feature = "array_windows", issue = "75027")] pub use iter::ArrayWindows; -#[unstable(feature = "slice_group_by", issue = "none")] +#[unstable(feature = "slice_group_by", issue = "80552")] pub use iter::{GroupBy, GroupByMut}; #[unstable(feature = "split_inclusive", issue = "72360")] @@ -1246,7 +1246,7 @@ impl [T] { /// assert_eq!(iter.next(), Some(&[2, 3, 4][..])); /// assert_eq!(iter.next(), None); /// ``` - #[unstable(feature = "slice_group_by", issue = "none")] + #[unstable(feature = "slice_group_by", issue = "80552")] #[inline] pub fn group_by(&self, pred: F) -> GroupBy<'_, T, F> where @@ -1291,7 +1291,7 @@ impl [T] { /// assert_eq!(iter.next(), Some(&mut [2, 3, 4][..])); /// assert_eq!(iter.next(), None); /// ``` - #[unstable(feature = "slice_group_by", issue = "none")] + #[unstable(feature = "slice_group_by", issue = "80552")] #[inline] pub fn group_by_mut(&mut self, pred: F) -> GroupByMut<'_, T, F> where -- cgit 1.4.1-3-g733a5