mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
33 lines
633 B
Rust
33 lines
633 B
Rust
|
use std::fmt;
|
||
|
|
||
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||
|
pub struct TextUnit(u32);
|
||
|
|
||
|
impl TextUnit {
|
||
|
pub fn len_of_char(c: char) -> TextUnit {
|
||
|
TextUnit(c.len_utf8() as u32)
|
||
|
}
|
||
|
|
||
|
pub fn new(val: u32) -> TextUnit {
|
||
|
TextUnit(val)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl fmt::Debug for TextUnit {
|
||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||
|
<Self as fmt::Display>::fmt(self, f)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl fmt::Display for TextUnit {
|
||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||
|
self.0.fmt(f)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl From<TextUnit> for u32 {
|
||
|
fn from(tu: TextUnit) -> u32 {
|
||
|
tu.0
|
||
|
}
|
||
|
}
|