Function text_diff_changes

Source
pub fn text_diff_changes(old: &str, new: &str) -> Vec<(ChangeTag, String)>
Expand description

Computes the differences between two strings line by line and returns a vector of changes.

Each change is represented as a tuple containing a ChangeTag indicating the type of change (deletion, insertion, or equality) and a String with the formatted line prefixed with a symbol indicating the type of change (- for deletions, + for insertions, and a space for equal lines).

The formatted string is also colored: red for deletions, green for insertions, and dimmed for equal lines.

§Arguments

  • old - A string slice representing the original text.
  • new - A string slice representing the modified text.

§Returns

A vector of tuples, each containing a ChangeTag and a formatted String representing the changes.