1use std::ops::{Add, AddAssign, Sub};
2
3#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd)]
4pub struct OffsetUtf16(pub usize);
5
6impl<'a> Add<&'a Self> for OffsetUtf16 {
7 type Output = Self;
8
9 fn add(self, other: &'a Self) -> Self::Output {
10 Self(self.0 + other.0)
11 }
12}
13
14impl Add for OffsetUtf16 {
15 type Output = Self;
16
17 fn add(self, other: Self) -> Self::Output {
18 Self(self.0 + other.0)
19 }
20}
21
22impl<'a> Sub<&'a Self> for OffsetUtf16 {
23 type Output = Self;
24
25 fn sub(self, other: &'a Self) -> Self::Output {
26 debug_assert!(*other <= self);
27 Self(self.0 - other.0)
28 }
29}
30
31impl Sub for OffsetUtf16 {
32 type Output = OffsetUtf16;
33
34 fn sub(self, other: Self) -> Self::Output {
35 debug_assert!(other <= self);
36 Self(self.0 - other.0)
37 }
38}
39
40impl<'a> AddAssign<&'a Self> for OffsetUtf16 {
41 fn add_assign(&mut self, other: &'a Self) {
42 self.0 += other.0;
43 }
44}
45
46impl AddAssign<Self> for OffsetUtf16 {
47 fn add_assign(&mut self, other: Self) {
48 self.0 += other.0;
49 }
50}