Skip to content

Commit d91f5a8

Browse files
committed
impl Debug for Map<_, [closure]>
This matches the (implementation for `core::iter::Map`)[0]. [0]: https://github.com/rust-lang/rust/blob/eac35583d2ffb5ed9e564dee0822c9a244058ee0/library/core/src/iter/adapters/map.rs#L73-L78
1 parent 707020c commit d91f5a8

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1073,12 +1073,18 @@ where
10731073

10741074
/// An iterator which applies a fallible transform to the elements of the
10751075
/// underlying iterator.
1076-
#[derive(Clone, Debug)]
1076+
#[derive(Clone)]
10771077
pub struct Map<T, F> {
10781078
it: T,
10791079
f: F,
10801080
}
10811081

1082+
impl<I: core::fmt::Debug, F> core::fmt::Debug for Map<I, F> {
1083+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1084+
f.debug_struct("Map").field("iter", &self.it).finish()
1085+
}
1086+
}
1087+
10821088
impl<T, F, B> FallibleIterator for Map<T, F>
10831089
where
10841090
T: FallibleIterator,

src/test.rs

+2
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ fn last() {
190190
#[test]
191191
fn map() {
192192
let it = convert(vec![0, 1, 2, 3, 4].into_iter().map(Ok::<u32, ()>)).map(|n| Ok(n * 2));
193+
fn assert_debug(_: &impl core::fmt::Debug) {}
194+
assert_debug(&it);
193195
assert_eq!(it.clone().collect::<Vec<_>>().unwrap(), [0, 2, 4, 6, 8]);
194196
assert_eq!(it.rev().collect::<Vec<_>>().unwrap(), [8, 6, 4, 2, 0]);
195197

0 commit comments

Comments
 (0)