|
4 | 4 | }; |
5 | 5 |
|
6 | 6 | /// Text-like structures that have a text size. |
7 | | -pub trait LenTextSize: Copy { |
| 7 | +pub trait TextLen: Copy { |
8 | 8 | /// The size of this text-alike. |
9 | | - fn len_text_size(self) -> TextSize; |
| 9 | + fn text_len(self) -> TextSize; |
10 | 10 | } |
11 | 11 |
|
12 | | -impl LenTextSize for &'_ str { |
| 12 | +impl TextLen for &'_ str { |
13 | 13 | #[inline] |
14 | | - fn len_text_size(self) -> TextSize { |
| 14 | + fn text_len(self) -> TextSize { |
15 | 15 | self.len().try_into().unwrap() |
16 | 16 | } |
17 | 17 | } |
18 | 18 |
|
19 | | -impl LenTextSize for char { |
| 19 | +impl TextLen for char { |
20 | 20 | #[inline] |
21 | | - fn len_text_size(self) -> TextSize { |
| 21 | + fn text_len(self) -> TextSize { |
22 | 22 | (self.len_utf8() as u32).into() |
23 | 23 | } |
24 | 24 | } |
25 | 25 |
|
26 | | -impl<D> LenTextSize for &'_ D |
| 26 | +impl<D> TextLen for &'_ D |
27 | 27 | where |
28 | | - D: LenTextSize + Copy, |
| 28 | + D: TextLen + Copy, |
29 | 29 | { |
30 | | - fn len_text_size(self) -> TextSize { |
31 | | - D::len_text_size(*self) |
| 30 | + fn text_len(self) -> TextSize { |
| 31 | + D::text_len(*self) |
32 | 32 | } |
33 | 33 | } |
34 | 34 |
|
35 | 35 | // Because we could not find a smart blanket impl to do this automatically and |
36 | 36 | // cleanly (rust-analyzer/text-size#36), just provide a bunch of manual impls. |
37 | | -// If a type fits in this macro and you need it to impl LenTextSize, just open |
38 | | -// a PR and we are likely to accept it. Or use `TextSize::of::<&str>` for now. |
39 | | -macro_rules! impl_lentextsize_for_string { |
| 37 | +// If a standard type fits in this macro and you need it to impl TextLen, just |
| 38 | +// open a PR and we are likely to accept it. Or convince Rust to deref to &str. |
| 39 | +macro_rules! impl_textlen_for_string { |
40 | 40 | ($($ty:ty),+ $(,)?) => {$( |
41 | | - impl LenTextSize for $ty { |
| 41 | + impl TextLen for $ty { |
42 | 42 | #[inline] |
43 | | - fn len_text_size(self) -> TextSize { |
44 | | - <&str>::len_text_size(self) |
| 43 | + fn text_len(self) -> TextSize { |
| 44 | + <&str>::text_len(self) |
45 | 45 | } |
46 | 46 | } |
47 | 47 | )+}; |
48 | 48 | } |
49 | 49 |
|
50 | | -impl_lentextsize_for_string! { |
| 50 | +impl_textlen_for_string! { |
51 | 51 | &Box<str>, |
52 | | - &'_ String, |
| 52 | + &String, |
53 | 53 | &Cow<'_, str>, |
54 | 54 | &Cow<'_, String>, |
55 | 55 | &Arc<str>, |
|
0 commit comments