basic/
basic.rs

1//! Uses the `visit_diff::debug` module to print differences between two data
2//! structures in `Debug` format.
3
4use visit_diff::debug_diff;
5use visit_diff::Diff;
6
7////////////////////////////////////////////////////////////////////////////////
8// Arbitrary example data structure.
9
10#[derive(Debug, Diff)]
11struct Newtype(Top);
12
13#[derive(Debug, Diff)]
14struct Top {
15    pub child1: Child1,
16    pub others: Vec<Other>,
17}
18
19#[derive(Debug, Diff)]
20struct Child1 {
21    pub name: &'static str,
22    pub size: usize,
23}
24
25#[derive(Debug, Diff)]
26enum Other {
27    Prince,
28    Bob { last_name: &'static str },
29}
30
31////////////////////////////////////////////////////////////////////////////////
32// Actual code.
33
34fn main() {
35    let a = Newtype(Top {
36        child1: Child1 {
37            name: "Sprocket",
38            size: 12,
39        },
40        others: vec![
41            Other::Prince,
42            Other::Bob {
43                last_name: "Roberts",
44            },
45        ],
46    });
47
48    let b = Newtype(Top {
49        // Note: both name and size are different.
50        child1: Child1 {
51            name: "Ralph",
52            size: usize::max_value(),
53        },
54        others: vec![
55            Other::Prince,
56            Other::Bob {
57                last_name: "Roberts",
58            },
59            // added
60            Other::Bob {
61                last_name: "Bobberson",
62            },
63        ],
64    });
65
66    println!("{:#?}", debug_diff(a, b));
67}