exec_diff/
diff.rs

1use super::Color;
2
3/// The diff executor.
4///
5/// This is a wrapper around the GNU `diff` command.
6#[derive(Debug, Clone, Copy)]
7pub struct Diff<Left, Right> {
8    /// Value on the left.
9    pub left: Left,
10    /// Value on the right.
11    pub right: Right,
12    /// Whether to include ANSI color in the diff.
13    pub color: Color,
14    /// Whether to use the unified diff format.
15    pub unified: bool,
16}
17
18impl<Left, Right> Diff<Left, Right> {
19    /// Initialize a diff executor.
20    pub const fn new(left: Left, right: Right) -> Self {
21        Diff {
22            left,
23            right,
24            color: Color::Always,
25            unified: true,
26        }
27    }
28
29    /// Set the left value.
30    pub fn left<NewLeft>(self, left: NewLeft) -> Diff<NewLeft, Right> {
31        let Diff {
32            left: _,
33            right,
34            color,
35            unified,
36        } = self;
37        Diff {
38            left,
39            right,
40            color,
41            unified,
42        }
43    }
44
45    /// Set the right value.
46    pub fn right<NewRight>(self, right: NewRight) -> Diff<Left, NewRight> {
47        let Diff {
48            left,
49            right: _,
50            color,
51            unified,
52        } = self;
53        Diff {
54            left,
55            right,
56            color,
57            unified,
58        }
59    }
60
61    /// Set color mode. Default is [`Color::Always`].
62    pub const fn color(mut self, color: Color) -> Self {
63        self.color = color;
64        self
65    }
66
67    /// Set diff format. Default is `true`.
68    pub const fn unified(mut self, unified: bool) -> Self {
69        self.unified = unified;
70        self
71    }
72}