Skip to content

Commit

Permalink
Debug Diff
Browse files Browse the repository at this point in the history
We can not derive Debug.
I checked, an usual debugged enum does not display the name of the type but only the variant name.
  • Loading branch information
Philippe-Cholet committed Jan 16, 2024
1 parent f60fe7e commit 0c606cc
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//! describes the difference between two non-`Clone` iterators `I` and `J` after breaking ASAP from
//! a lock-step comparison.
use std::fmt;

use crate::free::put_back;
use crate::structs::PutBack;

Expand All @@ -26,6 +28,27 @@ where
Longer(usize, PutBack<J>),
}

impl<I, J> fmt::Debug for Diff<I, J>
where
I: Iterator,
J: Iterator,
PutBack<I>: fmt::Debug,
PutBack<J>: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::FirstMismatch(idx, i, j) => f
.debug_tuple("FirstMismatch")
.field(idx)
.field(i)
.field(j)
.finish(),
Self::Shorter(idx, i) => f.debug_tuple("Shorter").field(idx).field(i).finish(),
Self::Longer(idx, j) => f.debug_tuple("Longer").field(idx).field(j).finish(),
}
}
}

/// Compares every element yielded by both `i` and `j` with the given function in lock-step and
/// returns a [`Diff`] which describes how `j` differs from `i`.
///
Expand Down

0 comments on commit 0c606cc

Please sign in to comment.