Function similar::utils::diff_graphemes
source ยท pub fn diff_graphemes<'x, T: DiffableStrRef + ?Sized>(
alg: Algorithm,
old: &'x T,
new: &'x T,
) -> Vec<(ChangeTag, &'x T::Output)>
Expand description
Shortcut for making a grapheme 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 grapheme level slices.
use similar::{Algorithm, ChangeTag};
use similar::utils::diff_graphemes;
let old = "The flag of Austria is ๐ฆ๐น";
let new = "The flag of Albania is ๐ฆ๐ฑ";
assert_eq!(diff_graphemes(Algorithm::Myers, old, new), vec![
(ChangeTag::Equal, "The flag of A"),
(ChangeTag::Delete, "ustr"),
(ChangeTag::Insert, "lban"),
(ChangeTag::Equal, "ia is "),
(ChangeTag::Delete, "๐ฆ๐น"),
(ChangeTag::Insert, "๐ฆ๐ฑ"),
]);
This requires the unicode
feature.