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 pub fn checked_sub(self, other: $row) -> Option<$row_delta> {
46 self.0.checked_sub(other.0).map($row_delta)
47 }
48 }
49
50 impl ::std::ops::Add for $row {
51 type Output = Self;
52
53 fn add(self, rhs: Self) -> Self::Output {
54 Self(self.0 + rhs.0)
55 }
56 }
57
58 impl ::std::ops::Add<$row_delta> for $row {
59 type Output = Self;
60
61 fn add(self, rhs: $row_delta) -> Self::Output {
62 Self(self.0 + rhs.0)
63 }
64 }
65
66 impl ::std::ops::Sub for $row {
67 type Output = $row_delta;
68
69 fn sub(self, rhs: Self) -> Self::Output {
70 $row_delta(self.0 - rhs.0)
71 }
72 }
73
74 impl ::std::ops::Sub<$row_delta> for $row {
75 type Output = $row;
76
77 fn sub(self, rhs: $row_delta) -> Self::Output {
78 $row(self.0 - rhs.0)
79 }
80 }
81
82 impl ::std::ops::AddAssign for $row {
83 fn add_assign(&mut self, rhs: Self) {
84 self.0 += rhs.0;
85 }
86 }
87
88 impl ::std::ops::AddAssign<$row_delta> for $row {
89 fn add_assign(&mut self, rhs: $row_delta) {
90 self.0 += rhs.0;
91 }
92 }
93
94 impl ::std::ops::SubAssign<$row_delta> for $row {
95 fn sub_assign(&mut self, rhs: $row_delta) {
96 self.0 -= rhs.0;
97 }
98 }
99 };
100}