-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add an example that diffs two files passed as args
- Loading branch information
1 parent
9a4f55d
commit 4f5fac9
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} | ||
} | ||
} |