pub struct Differ<'c, T> { /* private fields */ }Expand description
A configurable diff, for when diff isn’t enough.
use fastanim_diff::{Differ, Op};
let a = ["a", "²", "+", "b", "²", "=", "c", "²"];
let b = ["a", "²", "=", "c", "²", "-", "b", "²"];
let ops = Differ::new(&a, &b, |t| *t)
.class(|t| matches!(*t, "+" | "-").then_some("operator"))
.run();
assert!(ops.contains(&Op::Replace { a: 2..3, b: 5..6 }));Implementations§
Source§impl<'c, T> Differ<'c, T>
impl<'c, T> Differ<'c, T>
Sourcepub fn new<K: Eq + Hash>(a: &'c [T], b: &'c [T], key: impl Fn(&T) -> K) -> Self
pub fn new<K: Eq + Hash>(a: &'c [T], b: &'c [T], key: impl Fn(&T) -> K) -> Self
Prepares a diff of a against b, comparing items by key.
Sourcepub fn options(self, opts: DiffOptions) -> Self
pub fn options(self, opts: DiffOptions) -> Self
Sets the options.
Sourcepub fn cost(self, cost: impl Fn(usize, usize) -> f64 + 'c) -> Self
pub fn cost(self, cost: impl Fn(usize, usize) -> f64 + 'c) -> Self
Sets the cost of pairing a[i] with b[j] in move detection and cross-hunk
replacement pairing, typically the distance between their centroids. Lower is better.
Defaults to the index distance |i - j|.
Auto Trait Implementations§
impl<'c, T> !RefUnwindSafe for Differ<'c, T>
impl<'c, T> !Send for Differ<'c, T>
impl<'c, T> !Sync for Differ<'c, T>
impl<'c, T> !UnwindSafe for Differ<'c, T>
impl<'c, T> Freeze for Differ<'c, T>
impl<'c, T> Unpin for Differ<'c, T>
impl<'c, T> UnsafeUnpin for Differ<'c, T>where
&'c [T]: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more