Skip to main content

diff_strings

Function diff_strings 

Source
pub fn diff_strings(left: &str, right: &str) -> String
Expand description

Returns a formatted line-by-line diff of two strings with ANSI color codes.

Removed lines are shown in red with a - prefix, added lines in green with a + prefix, and unchanged lines with a prefix.

If the NO_COLOR environment variable is set, colors are omitted (equivalent to calling diff_strings_no_color).

ยงExamples

use philiprehberger_diff_assert::diff_strings;

let result = diff_strings("hello\nworld", "hello\neveryone");
// result contains a colored diff showing "world" removed and "everyone" added