Skip to content

Commit 0c606cc

Browse files
Debug Diff
We can not derive Debug. I checked, an usual debugged enum does not display the name of the type but only the variant name.
1 parent f60fe7e commit 0c606cc

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/diff.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
//! describes the difference between two non-`Clone` iterators `I` and `J` after breaking ASAP from
66
//! a lock-step comparison.
77
8+
use std::fmt;
9+
810
use crate::free::put_back;
911
use crate::structs::PutBack;
1012

@@ -26,6 +28,27 @@ where
2628
Longer(usize, PutBack<J>),
2729
}
2830

31+
impl<I, J> fmt::Debug for Diff<I, J>
32+
where
33+
I: Iterator,
34+
J: Iterator,
35+
PutBack<I>: fmt::Debug,
36+
PutBack<J>: fmt::Debug,
37+
{
38+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39+
match self {
40+
Self::FirstMismatch(idx, i, j) => f
41+
.debug_tuple("FirstMismatch")
42+
.field(idx)
43+
.field(i)
44+
.field(j)
45+
.finish(),
46+
Self::Shorter(idx, i) => f.debug_tuple("Shorter").field(idx).field(i).finish(),
47+
Self::Longer(idx, j) => f.debug_tuple("Longer").field(idx).field(j).finish(),
48+
}
49+
}
50+
}
51+
2952
/// Compares every element yielded by both `i` and `j` with the given function in lock-step and
3053
/// returns a [`Diff`] which describes how `j` differs from `i`.
3154
///

0 commit comments

Comments
 (0)