osom_primitives/
offset_ops.rs

1use crate::{as_i32::AsI32, offset::Offset};
2
3impl AsI32 for Offset {
4    fn as_i32(&self) -> i32 {
5        Offset::as_i32(self)
6    }
7}
8
9impl<T: AsI32> core::ops::Add<T> for Offset {
10    type Output = Self;
11
12    fn add(self, rhs: T) -> Self::Output {
13        unsafe { Self::new_unchecked(self.as_i32() + rhs.as_i32()) }
14    }
15}
16
17impl<T: AsI32> core::ops::AddAssign<T> for Offset {
18    fn add_assign(&mut self, rhs: T) {
19        *self = unsafe { Self::new_unchecked(self.as_i32() + rhs.as_i32()) };
20    }
21}
22
23impl<T: AsI32> core::ops::Sub<T> for Offset {
24    type Output = Self;
25
26    fn sub(self, rhs: T) -> Self::Output {
27        unsafe { Self::new_unchecked(self.as_i32() - rhs.as_i32()) }
28    }
29}
30
31impl<T: AsI32> core::ops::SubAssign<T> for Offset {
32    fn sub_assign(&mut self, rhs: T) {
33        *self = unsafe { Self::new_unchecked(self.as_i32() - rhs.as_i32()) };
34    }
35}