tempa/frame_index/
impl_ops.rs1use core::ops::{Add, AddAssign, Sub, SubAssign};
2
3use rinia::numeric::{SaturatingAdd, SaturatingSub};
4
5use crate::FrameIndex;
6
7impl<T> Add for FrameIndex<T>
9where
10 T: Add<Output = T>,
11{
12 type Output = Self;
13
14 #[inline]
15 fn add(self, rhs: Self) -> Self::Output {
16 Self(self.0 + rhs.0)
17 }
18}
19
20impl<T> AddAssign for FrameIndex<T>
22where
23 T: AddAssign,
24{
25 #[inline]
26 fn add_assign(&mut self, rhs: Self) {
27 self.0 += rhs.0;
28 }
29}
30
31impl<T> Sub for FrameIndex<T>
33where
34 T: Sub<Output = T>,
35{
36 type Output = Self;
37
38 #[inline]
39 fn sub(self, rhs: Self) -> Self::Output {
40 Self(self.0 - rhs.0)
41 }
42}
43
44impl<T> SubAssign for FrameIndex<T>
46where
47 T: SubAssign,
48{
49 #[inline]
50 fn sub_assign(&mut self, rhs: Self) {
51 self.0 -= rhs.0;
52 }
53}
54
55impl<T> Add<T> for FrameIndex<T>
57where
58 T: Add<Output = T>,
59{
60 type Output = Self;
61
62 #[inline]
63 fn add(self, rhs: T) -> Self::Output {
64 Self(self.0 + rhs)
65 }
66}
67
68impl<T> AddAssign<T> for FrameIndex<T>
70where
71 T: AddAssign,
72{
73 #[inline]
74 fn add_assign(&mut self, rhs: T) {
75 self.0 += rhs;
76 }
77}
78
79impl<T> Sub<T> for FrameIndex<T>
81where
82 T: Sub<Output = T>,
83{
84 type Output = Self;
85
86 #[inline]
87 fn sub(self, rhs: T) -> Self::Output {
88 Self(self.0 - rhs)
89 }
90}
91
92impl<T> SubAssign<T> for FrameIndex<T>
94where
95 T: SubAssign,
96{
97 #[inline]
98 fn sub_assign(&mut self, rhs: T) {
99 self.0 -= rhs;
100 }
101}
102
103impl<T> FrameIndex<T>
105where
106 T: SaturatingAdd<Output = T>,
107{
108 #[inline]
110 pub fn saturating_add(self, rhs: Self) -> Self {
111 let value = self.0.saturating_add(rhs.0);
112 Self(value)
113 }
114
115 #[inline]
117 pub fn saturating_add_t(self, rhs: T) -> Self {
118 let value = self.0.saturating_add(rhs);
119 Self(value)
120 }
121}
122
123impl<T> SaturatingAdd for FrameIndex<T>
125where
126 T: SaturatingAdd<Output = T>,
127{
128 type Output = Self;
129
130 #[inline]
131 fn saturating_add(self, rhs: Self) -> Self::Output {
132 FrameIndex::saturating_add(self, rhs)
133 }
134}
135
136impl<T> SaturatingAdd<T> for FrameIndex<T>
138where
139 T: SaturatingAdd<Output = T>,
140{
141 type Output = Self;
142
143 #[inline]
144 fn saturating_add(self, rhs: T) -> Self::Output {
145 FrameIndex::saturating_add_t(self, rhs)
146 }
147}
148
149impl<T> FrameIndex<T>
151where
152 T: SaturatingSub<Output = T>,
153{
154 #[inline]
156 pub fn saturating_sub(self, rhs: Self) -> Self {
157 let value = self.0.saturating_sub(rhs.0);
158 Self(value)
159 }
160
161 #[inline]
163 pub fn saturating_sub_t(self, rhs: T) -> Self {
164 let value = self.0.saturating_sub(rhs);
165 Self(value)
166 }
167}
168
169impl<T> SaturatingSub for FrameIndex<T>
171where
172 T: SaturatingSub<Output = T>,
173{
174 type Output = Self;
175
176 #[inline]
177 fn saturating_sub(self, rhs: Self) -> Self::Output {
178 FrameIndex::saturating_sub(self, rhs)
179 }
180}
181
182impl<T> SaturatingSub<T> for FrameIndex<T>
184where
185 T: SaturatingSub<Output = T>,
186{
187 type Output = Self;
188
189 #[inline]
190 fn saturating_sub(self, rhs: T) -> Self::Output {
191 FrameIndex::saturating_sub_t(self, rhs)
192 }
193}