Function similar::utils::diff_chars
source ยท pub fn diff_chars<'x, T: DiffableStrRef + ?Sized>(
alg: Algorithm,
old: &'x T,
new: &'x T,
) -> Vec<(ChangeTag, &'x T::Output)>
Expand description
Shortcut for making a character 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 character level slices.
use similar::{Algorithm, ChangeTag};
use similar::utils::diff_chars;
assert_eq!(diff_chars(Algorithm::Myers, "foobarbaz", "fooBARbaz"), vec![
(ChangeTag::Equal, "foo"),
(ChangeTag::Delete, "bar"),
(ChangeTag::Insert, "BAR"),
(ChangeTag::Equal, "baz"),
]);