Unnamed repository; edit this file 'description' to name the repository.
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
use {
    crate::{TextRange, TextSize},
    std::convert::TryInto,
};

/// Text-like structures that have a text size.
pub trait TextSized {
    /// The size of this text-alike.
    fn text_size(&self) -> TextSize;
}

impl TextSized for str {
    fn text_size(&self) -> TextSize {
        let len = self.len();
        TextSize::new(len)
    }
}

impl TextSized for char {
    fn text_size(&self) -> TextSize {
        self.len_utf8().try_into().unwrap()
    }
}

impl TextSized for TextRange {
    fn text_size(&self) -> TextSize {
        self.len()
    }
}