1extern crate difflib;
2
3use difflib::differ::Differ;
4use difflib::sequencematcher::SequenceMatcher;
5
6fn main() {
7 // unified_diff
8 let first_text = "one two three four".split(" ").collect::<Vec<&str>>();
9 let second_text = "zero one tree four".split(" ").collect::<Vec<&str>>();
10 let diff = difflib::unified_diff(
11 &first_text,
12 &second_text,
13 "Original",
14 "Current",
15 "2005-01-26 23:30:50",
16 "2010-04-02 10:20:52",
17 3,
18 );
19 for line in &diff {
20 println!("{:?}", line);
21 }
22
23 //context_diff
24 let diff = difflib::context_diff(
25 &first_text,
26 &second_text,
27 "Original",
28 "Current",
29 "2005-01-26 23:30:50",
30 "2010-04-02 10:20:52",
31 3,
32 );
33 for line in &diff {
34 println!("{:?}", line);
35 }
36
37 //get_close_matches
38 let words = vec!["ape", "apple", "peach", "puppy"];
39 let result = difflib::get_close_matches("appel", words, 3, 0.6);
40 println!("{:?}", result);
41
42 //Differ examples
43 let differ = Differ::new();
44 let diff = differ.compare(&first_text, &second_text);
45 for line in &diff {
46 println!("{:?}", line);
47 }
48
49 //SequenceMatcher examples
50 let mut matcher = SequenceMatcher::new("one two three four", "zero one tree four");
51 let m = matcher.find_longest_match(0, 18, 0, 18);
52 println!("{:?}", m);
53 let all_matches = matcher.get_matching_blocks();
54 println!("{:?}", all_matches);
55 let opcode = matcher.get_opcodes();
56 println!("{:?}", opcode);
57 let grouped_opcodes = matcher.get_grouped_opcodes(2);
58 println!("{:?}", grouped_opcodes);
59 let ratio = matcher.ratio();
60 println!("{:?}", ratio);
61 matcher.set_seqs("aaaaa", "aaaab");
62 println!("{:?}", matcher.ratio());
63}
64