Skip to main content

diff

Function diff 

Source
pub fn diff<C, I>(old: C, new: C) -> SeqDelta<I>
where C: IntoIterator<Item = I>, I: Hash + Eq,
Expand description

Computes a minimal edit script turning old into new.

Returns an empty SeqDelta when the two are identical. Items need Hash + Eq rather than the PartialEq an unordered field asks for — that is what Myers’ implementation in similar requires to index the sequences, and it is why a sequence of floats cannot be an ordered field.

use delta_struct::seq::{diff, Splice};

let delta = diff(vec![1, 2, 3, 4], vec![1, 9, 3, 4]);
assert_eq!(
    delta.splices,
    vec![Splice { at: 1, remove: 1, insert: vec![9] }],
);