Skip to content

Commit

Permalink
add an example that diffs two files passed as args
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarshkukreti committed Feb 1, 2024
1 parent 9a4f55d commit 4f5fac9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions examples/diff.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
extern crate diff;

fn main() {
let args = std::env::args().collect::<Vec<_>>();

if args.len() != 3 {
println!("usage: cargo run --example diff <first file> <second file>");
std::process::exit(1);
}

let left = std::fs::read_to_string(&args[1]).unwrap();
let right = std::fs::read_to_string(&args[2]).unwrap();

for diff in diff::lines(&left, &right) {
match diff {
diff::Result::Left(l) => println!("-{}", l),
diff::Result::Both(l, _) => println!(" {}", l),
diff::Result::Right(r) => println!("+{}", r),
}
}
}

0 comments on commit 4f5fac9

Please sign in to comment.