Unnamed repository; edit this file 'description' to name the repository.
| -rw-r--r-- | lib/text-size/src/traits.rs | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/lib/text-size/src/traits.rs b/lib/text-size/src/traits.rs index d90f3d431c..7bfb586bad 100644 --- a/lib/text-size/src/traits.rs +++ b/lib/text-size/src/traits.rs @@ -8,14 +8,9 @@ pub trait TextSized: Copy { impl TextSized for &'_ str { fn text_size(self) -> TextSize { - let len = self.len(); - if let Ok(size) = len.try_into() { - size - } else if cfg!(debug_assertions) { - panic!("overflow when converting to TextSize"); - } else { - TextSize(len as u32) - } + self.len() + .try_into() + .unwrap_or_else(|| panic!("string too large ({}) for TextSize", self.len())) } } |