diff options
Diffstat (limited to 'src/text.rs')
-rw-r--r-- | src/text.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/text.rs b/src/text.rs new file mode 100644 index 000000000..5297275ed --- /dev/null +++ b/src/text.rs | |||
@@ -0,0 +1,32 @@ | |||
1 | use std::fmt; | ||
2 | |||
3 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
4 | pub struct TextUnit(u32); | ||
5 | |||
6 | impl TextUnit { | ||
7 | pub fn len_of_char(c: char) -> TextUnit { | ||
8 | TextUnit(c.len_utf8() as u32) | ||
9 | } | ||
10 | |||
11 | pub fn new(val: u32) -> TextUnit { | ||
12 | TextUnit(val) | ||
13 | } | ||
14 | } | ||
15 | |||
16 | impl fmt::Debug for TextUnit { | ||
17 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
18 | <Self as fmt::Display>::fmt(self, f) | ||
19 | } | ||
20 | } | ||
21 | |||
22 | impl fmt::Display for TextUnit { | ||
23 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
24 | self.0.fmt(f) | ||
25 | } | ||
26 | } | ||
27 | |||
28 | impl From<TextUnit> for u32 { | ||
29 | fn from(tu: TextUnit) -> u32 { | ||
30 | tu.0 | ||
31 | } | ||
32 | } | ||