diff options
author | Wilfred Hughes <me@wilfred.me.uk> | 2023-08-04 23:29:29 -0700 |
---|---|---|
committer | Wilfred Hughes <me@wilfred.me.uk> | 2023-08-04 23:29:29 -0700 |
commit | 19cbf1d45854e4648ea45b97e967c64f90c3b5c7 (patch) | |
tree | 388f36b42d8dda0c4442d9ed72a408c28301310f | |
parent | 892d4fdb5887e4aa7ba6a76c34987057518548ec (diff) |
Implement some other useful traits on EqOnFirstItem
These aren't immediately used, but they're handy for experimenting
with the similar library which requires these.
-rw-r--r-- | src/diff/unchanged.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/diff/unchanged.rs b/src/diff/unchanged.rs index a8332acda..2b3fce662 100644 --- a/src/diff/unchanged.rs +++ b/src/diff/unchanged.rs @@ -2,6 +2,7 @@ //! diff on smaller inputs. use std::collections::HashSet; +use std::hash::Hash; use crate::diff::changes::{insert_deep_unchanged, ChangeKind, ChangeMap}; use crate::diff::myers_diff; @@ -323,6 +324,24 @@ impl<X: Eq, Y> PartialEq for EqOnFirstItem<X, Y> { } impl<X: Eq, Y> Eq for EqOnFirstItem<X, Y> {} +impl<X: Eq + PartialOrd, Y> PartialOrd for EqOnFirstItem<X, Y> { + fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { + self.0.partial_cmp(&other.0) + } +} + +impl<X: Eq + Ord, Y> Ord for EqOnFirstItem<X, Y> { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.0.cmp(&other.0) + } +} + +impl<X: Hash, Y> Hash for EqOnFirstItem<X, Y> { + fn hash<H: std::hash::Hasher>(&self, state: &mut H) { + self.0.hash(state); + } +} + fn as_singleton_list_children<'a>( lhs_nodes: &[&'a Syntax<'a>], rhs_nodes: &[&'a Syntax<'a>], |