diff

Function diff 

Source
pub fn diff(
    w: &mut dyn Write,
    old: &str,
    new: &str,
    theme: &dyn Theme,
) -> Result<()>
Expand description

Print a diff to a writer

§Examples

Black and white output

use termdiff::{diff, ArrowsTheme};
let old = "a\nb\nc";
let new = "a\nc\n";
let mut buffer: Vec<u8> = Vec::new();
let theme = ArrowsTheme::default();
diff(&mut buffer, old, new, &theme).unwrap();
let actual: String = String::from_utf8(buffer).expect("Not valid UTF-8");

assert_eq!(
    actual,
    "< left / > right
 a
<b
<c
>c␊
"
);

Colorful theme

use termdiff::{diff, ArrowsColorTheme};
let old = "a\nb\nc";
let new = "a\nc\n";
let mut buffer: Vec<u8> = Vec::new();
let theme = ArrowsColorTheme::default();
diff(&mut buffer, old, new, &theme).unwrap();
let actual: String = String::from_utf8(buffer).expect("Not valid UTF-8");

assert_eq!(
    actual,
"\u{1b}[38;5;9m< left\u{1b}[39m / \u{1b}[38;5;10m> right\u{1b}[39m\n a\n\u{1b}[38;5;9m<\u{1b}[39m\u{1b}[38;5;9mb\n\u{1b}[39m\u{1b}[38;5;9m<\u{1b}[39m\u{1b}[38;5;9mc\u{1b}[39m\n\u{1b}[38;5;10m>\u{1b}[39m\u{1b}[38;5;10mc␊\n\u{1b}[39m",
);

§Errors

Errors on failing to write to the writer.