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 Self(self.0 - other.0)
36 }
37}
38
39impl<'a> AddAssign<&'a Self> for OffsetUtf16 {
40 fn add_assign(&mut self, other: &'a Self) {
41 self.0 += other.0;
42 }
43}
44
45impl AddAssign<Self> for OffsetUtf16 {
46 fn add_assign(&mut self, other: Self) {
47 self.0 += other.0;
48 }
49}