Skip to content

impl debug trait for diff enum#438

Closed
Zaba505 wants to merge 1 commit intorust-itertools:masterfrom
Zaba505:feat/diff-impl-debug
Closed

impl debug trait for diff enum#438
Zaba505 wants to merge 1 commit intorust-itertools:masterfrom
Zaba505:feat/diff-impl-debug

Conversation

@Zaba505
Copy link
Copy Markdown

@Zaba505 Zaba505 commented May 11, 2020

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
Copy link
Copy Markdown
Author

Zaba505 commented May 11, 2020

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.

@jswrenn
Copy link
Copy Markdown
Member

jswrenn commented May 12, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants