diff options
Diffstat (limited to 'src/text.rs')
-rw-r--r-- | src/text.rs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/text.rs b/src/text.rs index 5297275ed..31e67b456 100644 --- a/src/text.rs +++ b/src/text.rs | |||
@@ -1,7 +1,10 @@ | |||
1 | use std::fmt; | 1 | use std::fmt; |
2 | use std::ops; | ||
2 | 3 | ||
3 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 4 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
4 | pub struct TextUnit(u32); | 5 | pub struct TextUnit( |
6 | pub(crate) u32 | ||
7 | ); | ||
5 | 8 | ||
6 | impl TextUnit { | 9 | impl TextUnit { |
7 | pub fn len_of_char(c: char) -> TextUnit { | 10 | pub fn len_of_char(c: char) -> TextUnit { |
@@ -30,3 +33,29 @@ impl From<TextUnit> for u32 { | |||
30 | tu.0 | 33 | tu.0 |
31 | } | 34 | } |
32 | } | 35 | } |
36 | |||
37 | impl ops::Add<TextUnit> for TextUnit { | ||
38 | type Output = TextUnit; | ||
39 | fn add(self, rhs: TextUnit) -> TextUnit { | ||
40 | TextUnit(self.0 + rhs.0) | ||
41 | } | ||
42 | } | ||
43 | |||
44 | impl ops::AddAssign<TextUnit> for TextUnit { | ||
45 | fn add_assign(&mut self, rhs: TextUnit) { | ||
46 | self.0 += rhs.0 | ||
47 | } | ||
48 | } | ||
49 | |||
50 | impl ops::Sub<TextUnit> for TextUnit { | ||
51 | type Output = TextUnit; | ||
52 | fn sub(self, rhs: TextUnit) -> TextUnit { | ||
53 | TextUnit(self.0 - rhs.0) | ||
54 | } | ||
55 | } | ||
56 | |||
57 | impl ops::SubAssign<TextUnit> for TextUnit { | ||
58 | fn sub_assign(&mut self, rhs: TextUnit) { | ||
59 | self.0 -= rhs.0 | ||
60 | } | ||
61 | } \ No newline at end of file | ||