Side-by-side diff for two files in Rust. App && Library.
```rust use prettydiff::diff_slice;
println!("Diff: {}", diffslice(&[1, 2, 3, 4, 5, 6], &[2, 3, 5, 7])); println!( "Diff: {}", diffslice(&["q", "a", "b", "x", "c", "d"], &["a", "b", "y", "c", "d", "f"]) ); println!( "Diff: {}", diff_slice(&["a", "c", "d", "b"], &["a", "e", "b"]) ); ```
Get vector of changes:
```rust use prettydiff::diff_slice;
asserteq!( diffslice(&["q", "a", "b", "x", "c", "d"], &["a", "b", "y", "c", "d", "f"]).diff, vec![ DiffOp::Remove(&["q"]), DiffOp::Equal(&["a", "b"]), DiffOp::Replace(&["x"], &["y"]), DiffOp::Equal(&["c", "d"]), DiffOp::Insert(&["f"]), ] ); ```
```rust use prettydiff::{diffchars, diffwords};
println!("diffchars: {}", diffchars("abefcd", "zadqwc")); println!( "diffchars: {}", diffchars( "The quick brown fox jumps over the lazy dog", "The quick brown dog leaps over the lazy cat" ) ); println!( "diffchars: {}", diffchars( "The red brown fox jumped over the rolling log", "The brown spotted fox leaped over the rolling log" ) ); println!( "diffchars: {}", diffchars( "The red brown fox jumped over the rolling log", "The brown spotted fox leaped over the rolling log" ) .sethighlightwhitespace(true) ); println!( "diffwords: {}", diffwords( "The red brown fox jumped over the rolling log", "The brown spotted fox leaped over the rolling log" ) ); println!( "diffwords: {}", diffwords( "The quick brown fox jumps over the lazy dog", "The quick, brown dog leaps over the lazy cat" ) ); ```
```rust use prettydiff::diff_lines;
let code1_a = r#" void func1() { x += 1 }
void func2() { x += 2 } "#; let code1_b = r#" void func1(a: u32) { x += 1 }
void functhreehalves() { x += 1.5 }
void func2() { x += 2 }
void func3(){} "#; println!("difflines:"); println!("{}", difflines(code1a, code1b)); ```
This crate also provides app for side-by-side diff:
sh
cargo install prettydiff
prettydiff left_file.txt right_file.txt