Function similar::utils::diff_words
source ยท pub fn diff_words<'x, T: DiffableStrRef + ?Sized>(
alg: Algorithm,
old: &'x T,
new: &'x T,
) -> Vec<(ChangeTag, &'x T::Output)>
Expand description
Shortcut for making a word level diff.
This function produces the diff of two strings and returns a vector with the changes. It returns connected slices into the original string rather than word level slices.
use similar::{Algorithm, ChangeTag};
use similar::utils::diff_words;
assert_eq!(diff_words(Algorithm::Myers, "foo bar baz", "foo bor baz"), vec![
(ChangeTag::Equal, "foo "),
(ChangeTag::Delete, "bar"),
(ChangeTag::Insert, "bor"),
(ChangeTag::Equal, " baz"),
]);