Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'lib/text-size/src/traits.rs')
-rw-r--r--lib/text-size/src/traits.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/text-size/src/traits.rs b/lib/text-size/src/traits.rs
index ca4b7d9b42..fac1eccdc6 100644
--- a/lib/text-size/src/traits.rs
+++ b/lib/text-size/src/traits.rs
@@ -6,7 +6,10 @@ pub trait TextSized: Copy {
fn text_size(self) -> TextSize;
}
+/// This will panic for strings larger than `TextSize::MAX` when
+/// debug assertions are enabled, and wrap when they are disabled.
impl TextSized for &'_ str {
+ #[inline]
fn text_size(self) -> TextSize {
self.len()
.try_into()
@@ -15,6 +18,7 @@ impl TextSized for &'_ str {
}
impl TextSized for char {
+ #[inline]
fn text_size(self) -> TextSize {
TextSize(self.len_utf8() as u32)
}