1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::ops::{Add, AddAssign, Sub};

#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd)]
pub struct OffsetUtf16(pub usize);

impl<'a> Add<&'a Self> for OffsetUtf16 {
    type Output = Self;

    fn add(self, other: &'a Self) -> Self::Output {
        Self(self.0 + other.0)
    }
}

impl Add for OffsetUtf16 {
    type Output = Self;

    fn add(self, other: Self) -> Self::Output {
        Self(self.0 + other.0)
    }
}

impl<'a> Sub<&'a Self> for OffsetUtf16 {
    type Output = Self;

    fn sub(self, other: &'a Self) -> Self::Output {
        debug_assert!(*other <= self);
        Self(self.0 - other.0)
    }
}

impl Sub for OffsetUtf16 {
    type Output = OffsetUtf16;

    fn sub(self, other: Self) -> Self::Output {
        debug_assert!(other <= self);
        Self(self.0 - other.0)
    }
}

impl<'a> AddAssign<&'a Self> for OffsetUtf16 {
    fn add_assign(&mut self, other: &'a Self) {
        self.0 += other.0;
    }
}

impl AddAssign<Self> for OffsetUtf16 {
    fn add_assign(&mut self, other: Self) {
        self.0 += other.0;
    }
}