1#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)]
2pub struct RowDelta(pub u32);
3
4impl RowDelta {
5 pub fn saturating_sub(self, other: RowDelta) -> RowDelta {
6 RowDelta(self.0.saturating_sub(other.0))
7 }
8}
9
10impl ::std::ops::Add for RowDelta {
11 type Output = RowDelta;
12
13 fn add(self, rhs: RowDelta) -> Self::Output {
14 RowDelta(self.0 + rhs.0)
15 }
16}
17
18impl ::std::ops::Sub for RowDelta {
19 type Output = RowDelta;
20
21 fn sub(self, rhs: RowDelta) -> Self::Output {
22 RowDelta(self.0 - rhs.0)
23 }
24}
25
26impl ::std::ops::AddAssign for RowDelta {
27 fn add_assign(&mut self, rhs: RowDelta) {
28 self.0 += rhs.0;
29 }
30}
31
32impl ::std::ops::SubAssign for RowDelta {
33 fn sub_assign(&mut self, rhs: RowDelta) {
34 self.0 -= rhs.0;
35 }
36}
37
38macro_rules! impl_for_row_types {
39 ($row:ident => $row_delta:ident) => {
40 impl $row {
41 pub fn saturating_sub(self, other: $row_delta) -> $row {
42 $row(self.0.saturating_sub(other.0))
43 }
44 }
45
46 impl ::std::ops::Add for $row {
47 type Output = Self;
48
49 fn add(self, rhs: Self) -> Self::Output {
50 Self(self.0 + rhs.0)
51 }
52 }
53
54 impl ::std::ops::Add<$row_delta> for $row {
55 type Output = Self;
56
57 fn add(self, rhs: $row_delta) -> Self::Output {
58 Self(self.0 + rhs.0)
59 }
60 }
61
62 impl ::std::ops::Sub for $row {
63 type Output = $row_delta;
64
65 fn sub(self, rhs: Self) -> Self::Output {
66 $row_delta(self.0 - rhs.0)
67 }
68 }
69
70 impl ::std::ops::Sub<$row_delta> for $row {
71 type Output = $row;
72
73 fn sub(self, rhs: $row_delta) -> Self::Output {
74 $row(self.0 - rhs.0)
75 }
76 }
77
78 impl ::std::ops::AddAssign for $row {
79 fn add_assign(&mut self, rhs: Self) {
80 self.0 += rhs.0;
81 }
82 }
83
84 impl ::std::ops::AddAssign<$row_delta> for $row {
85 fn add_assign(&mut self, rhs: $row_delta) {
86 self.0 += rhs.0;
87 }
88 }
89
90 impl ::std::ops::SubAssign<$row_delta> for $row {
91 fn sub_assign(&mut self, rhs: $row_delta) {
92 self.0 -= rhs.0;
93 }
94 }
95 };
96}