aboutsummaryrefslogtreecommitdiff
path: root/src/text.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/text.rs')
-rw-r--r--src/text.rs31
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 @@
1use std::fmt; 1use std::fmt;
2use std::ops;
2 3
3#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 4#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
4pub struct TextUnit(u32); 5pub struct TextUnit(
6 pub(crate) u32
7);
5 8
6impl TextUnit { 9impl 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
37impl 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
44impl ops::AddAssign<TextUnit> for TextUnit {
45 fn add_assign(&mut self, rhs: TextUnit) {
46 self.0 += rhs.0
47 }
48}
49
50impl 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
57impl 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