itertools icon indicating copy to clipboard operation
itertools copied to clipboard

impl debug trait for diff enum

Open Zaba505 opened this issue 5 years ago • 2 comments

I added a fairly simple yet informative fmt::Debug implementation to the Diff enum. The reasoning behind this is to simplify tests where you just want to say:

// Diff some expected iter with the actual outputted one
let diff = itertools::diff_with(ex, out, |a, b| a == b);

// Now, all you care about is that there is no difference
// If there is, the index of the diff will be logged by assert_eq!
// since diff now impls fmt::Debug
assert_eq!(None, diff);

Zaba505 avatar May 11 '20 07:05 Zaba505

I just realized my sample scenario won't work even with the fmt::Debug impl since assert_eq! requires Eq/PartialEq to be implemented. If this PR is accepted, then I will open another providing a simple implementation of PartialEq.

Zaba505 avatar May 11 '20 07:05 Zaba505

I'd prefer a #[derive(Debug)] impl—the property that you can generally copy a debug output and paste it into source code is really useful!

If this PR is accepted, then I will open another providing a simple implementation of PartialEq.

Iterators usually don't provide a PartialEq implementation, so this wouldn't be very helpful.

jswrenn avatar May 12 '20 18:05 jswrenn