Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 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,43 @@ 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(),
}
}
}

impl<I, J> Clone for Diff<I, J>
where
I: Iterator,
J: Iterator,
PutBack<I>: Clone,
PutBack<J>: Clone,
{
fn clone(&self) -> Self {
match self {
Self::FirstMismatch(idx, i, j) => Self::FirstMismatch(*idx, i.clone(), j.clone()),
Self::Shorter(idx, i) => Self::Shorter(*idx, i.clone()),
Self::Longer(idx, j) => Self::Longer(*idx, j.clone()),
}
}
}

/// 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