diff --git a/lib/text-size/src/lib.rs b/lib/text-size/src/lib.rs index e194e2317b..aea1591003 100644 --- a/lib/text-size/src/lib.rs +++ b/lib/text-size/src/lib.rs @@ -12,7 +12,7 @@ mod traits; #[cfg(feature = "serde")] mod serde_impls; -pub use crate::{range::TextRange, size::TextSize, traits::TextSized}; +pub use crate::{range::TextRange, size::TextSize, traits::LenTextSize}; #[cfg(target_pointer_width = "16")] compile_error!("text-size assumes usize >= u32 and does not work on 16-bit targets"); diff --git a/lib/text-size/src/size.rs b/lib/text-size/src/size.rs index 14f7b37df0..16fd7d648d 100644 --- a/lib/text-size/src/size.rs +++ b/lib/text-size/src/size.rs @@ -1,5 +1,5 @@ use { - crate::TextSized, + crate::LenTextSize, std::{ convert::TryFrom, fmt, iter, @@ -42,8 +42,8 @@ impl fmt::Debug for TextSize { impl TextSize { /// The text size of some text-like object. #[inline] - pub fn of(text: impl TextSized) -> TextSize { - text.text_size() + pub fn of(text: impl LenTextSize) -> TextSize { + text.len_text_size() } /// A size of zero. diff --git a/lib/text-size/src/traits.rs b/lib/text-size/src/traits.rs index 6f3462bee5..745675fda7 100644 --- a/lib/text-size/src/traits.rs +++ b/lib/text-size/src/traits.rs @@ -4,33 +4,33 @@ use { }; /// Text-like structures that have a text size. -pub trait TextSized: Copy { +pub trait LenTextSize: Copy { /// The size of this text-alike. - fn text_size(self) -> TextSize; + fn len_text_size(self) -> TextSize; } -impl TextSized for &'_ str { +impl LenTextSize for &'_ str { #[inline] - fn text_size(self) -> TextSize { + fn len_text_size(self) -> TextSize { self.len() .try_into() .unwrap_or_else(|_| panic!("string too large ({}) for TextSize", self.len())) } } -impl TextSized for &'_ D +impl LenTextSize for &'_ D where D: Deref, { #[inline] - fn text_size(self) -> TextSize { - self.deref().text_size() + fn len_text_size(self) -> TextSize { + self.deref().len_text_size() } } -impl TextSized for char { +impl LenTextSize for char { #[inline] - fn text_size(self) -> TextSize { + fn len_text_size(self) -> TextSize { (self.len_utf8() as u32).into() } }