File: example.rs

package info (click to toggle)
rust-wu-diff 0.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 224 kB
  • sloc: makefile: 7
file content (29 lines) | stat: -rw-r--r-- 859 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
extern crate wu_diff;

use self::wu_diff::*;

fn main() {
    let old = vec!["foo", "bar", "baz"];
    let new = vec!["foo", "baz", "hoge"];

    for diff in wu_diff::diff(&old, &new) {
        match diff {
            DiffResult::Added(a) => {
                let i = a.new_index.unwrap();
                println!("+{} new index = {}", new[i], i)
            }
            DiffResult::Common(c) => {
                let new_index = c.new_index.unwrap();
                let old_index = c.old_index.unwrap();
                println!(
                    " {} old index = {}, new index = {}",
                    new[new_index], old_index, new_index
                )
            }
            DiffResult::Removed(r) => {
                let i = r.old_index.unwrap();
                println!("-{} old index = {}", old[i], i)
            }
        }
    }
}