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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use super::Color;

/// The diff executor.
///
/// This is a wrapper around the GNU `diff` command.
#[derive(Debug, Clone, Copy)]
pub struct Diff<Left, Right> {
    /// Value on the left.
    pub left: Left,
    /// Value on the right.
    pub right: Right,
    /// Whether to include ANSI color in the diff.
    pub color: Color,
    /// Whether to use the unified diff format.
    pub unified: bool,
}

impl<Left, Right> Diff<Left, Right> {
    /// Initialize a diff executor.
    pub const fn new(left: Left, right: Right) -> Self {
        Diff {
            left,
            right,
            color: Color::Always,
            unified: true,
        }
    }

    /// Set the left value.
    pub fn left<NewLeft>(self, left: NewLeft) -> Diff<NewLeft, Right> {
        let Diff {
            left: _,
            right,
            color,
            unified,
        } = self;
        Diff {
            left,
            right,
            color,
            unified,
        }
    }

    /// Set the right value.
    pub fn right<NewRight>(self, right: NewRight) -> Diff<Left, NewRight> {
        let Diff {
            left,
            right: _,
            color,
            unified,
        } = self;
        Diff {
            left,
            right,
            color,
            unified,
        }
    }

    /// Set color mode.
    pub const fn color(mut self, color: Color) -> Self {
        self.color = color;
        self
    }

    /// Set diff format.
    pub const fn unified(mut self, unified: bool) -> Self {
        self.unified = unified;
        self
    }
}