mitsuhiko / similar

A high level diffing library for rust based on diffs
https://insta.rs/similar
Apache License 2.0
971 stars 32 forks source link

New Trait Bounds #19

Open mitsuhiko opened 3 years ago

mitsuhiko commented 3 years ago

One of the behaviors inherited from pijul are many of the original trait bounds. Unfortunately these make things quite hard to improve various aspects of the implementation. In particular for instance the main inputs for the diff functions look something like this:

pub fn diff<Old, New, D>(
    d: &mut D,
    old: &Old,
    old_range: Range<usize>,
    new: &New,
    new_range: Range<usize>,
) -> Result<(), D::Error>
where
    Old: Index<usize> + ?Sized,
    New: Index<usize> + ?Sized,
    D: DiffHook,
    New::Output: PartialEq<Old::Output>,
{
  // ...
}

There are two issues with this that need to be solved:

mitsuhiko commented 3 years ago

The first issue is not as problematic. There is now a type called IdentifyDistinct which can work with the current trait bounds and still produces unique IDs for them.