Function similar::utils::diff_slices
source ยท pub fn diff_slices<'x, T: PartialEq + Hash + Ord>(
alg: Algorithm,
old: &'x [T],
new: &'x [T],
) -> Vec<(ChangeTag, &'x [T])>
Expand description
Shortcut for diffing two slices.
This function produces the diff of two slices and returns a vector with the changes.
use similar::{Algorithm, ChangeTag};
use similar::utils::diff_slices;
let old = "foo\nbar\nbaz".lines().collect::<Vec<_>>();
let new = "foo\nbar\nBAZ".lines().collect::<Vec<_>>();
assert_eq!(diff_slices(Algorithm::Myers, &old, &new), vec![
(ChangeTag::Equal, &["foo", "bar"][..]),
(ChangeTag::Delete, &["baz"][..]),
(ChangeTag::Insert, &["BAZ"][..]),
]);