Skip to content

Commit b2a7076

Browse files
committed
Implement a user friendly Debug on GroupBy and GroupByMut
1 parent 7952ea5 commit b2a7076

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

library/core/src/slice/iter.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -2976,7 +2976,6 @@ unsafe impl<'a, T> TrustedRandomAccess for IterMut<'a, T> {
29762976
/// [`group_by`]: ../../std/primitive.slice.html#method.group_by
29772977
/// [slices]: ../../std/primitive.slice.html
29782978
#[unstable(feature = "slice_group_by", issue = "none")]
2979-
#[derive(Debug)] // FIXME implement Debug to be more user friendly
29802979
pub struct GroupBy<'a, T: 'a, P> {
29812980
slice: &'a [T],
29822981
predicate: P,
@@ -3048,6 +3047,13 @@ where
30483047
#[unstable(feature = "slice_group_by", issue = "none")]
30493048
impl<'a, T: 'a, P> FusedIterator for GroupBy<'a, T, P> where P: FnMut(&T, &T) -> bool {}
30503049

3050+
#[unstable(feature = "slice_group_by", issue = "none")]
3051+
impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for GroupBy<'a, T, P> {
3052+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3053+
f.debug_struct("GroupBy").field("slice", &self.slice).finish()
3054+
}
3055+
}
3056+
30513057
/// An iterator over slice in (non-overlapping) mutable chunks separated
30523058
/// by a predicate.
30533059
///
@@ -3056,7 +3062,6 @@ impl<'a, T: 'a, P> FusedIterator for GroupBy<'a, T, P> where P: FnMut(&T, &T) ->
30563062
/// [`group_by_mut`]: ../../std/primitive.slice.html#method.group_by_mut
30573063
/// [slices]: ../../std/primitive.slice.html
30583064
#[unstable(feature = "slice_group_by", issue = "none")]
3059-
#[derive(Debug)] // FIXME implement Debug to be more user friendly
30603065
pub struct GroupByMut<'a, T: 'a, P> {
30613066
slice: &'a mut [T],
30623067
predicate: P,
@@ -3129,3 +3134,10 @@ where
31293134

31303135
#[unstable(feature = "slice_group_by", issue = "none")]
31313136
impl<'a, T: 'a, P> FusedIterator for GroupByMut<'a, T, P> where P: FnMut(&T, &T) -> bool {}
3137+
3138+
#[unstable(feature = "slice_group_by", issue = "none")]
3139+
impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for GroupByMut<'a, T, P> {
3140+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3141+
f.debug_struct("GroupByMut").field("slice", &self.slice).finish()
3142+
}
3143+
}

0 commit comments

Comments
 (0)