Skip to content

Commit e523b86

Browse files
bors[bot]CAD97
andauthored
Merge #20
20: Don't silently wrap for too-large str r=matklad a=CAD97 Closes #19 Co-authored-by: CAD97 <[email protected]> Co-authored-by: Christopher Durham <[email protected]>
2 parents d05705c + 0467db5 commit e523b86

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/traits.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@ pub trait TextSized: Copy {
88

99
impl TextSized for &'_ str {
1010
fn text_size(self) -> TextSize {
11-
let len = self.len();
12-
if let Ok(size) = len.try_into() {
13-
size
14-
} else if cfg!(debug_assertions) {
15-
panic!("overflow when converting to TextSize");
16-
} else {
17-
TextSize(len as u32)
18-
}
11+
self.len()
12+
.try_into()
13+
.unwrap_or_else(|_| panic!("string too large ({}) for TextSize", self.len()))
1914
}
2015
}
2116

0 commit comments

Comments
 (0)