Skip to content

Commit d89af64

Browse files
committed
make split_at_mut similar to split_at and use the checked function
1 parent febca57 commit d89af64

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

library/core/src/str/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -678,12 +678,9 @@ impl str {
678678
#[must_use]
679679
#[stable(feature = "str_split_at", since = "1.4.0")]
680680
pub fn split_at_mut(&mut self, mid: usize) -> (&mut str, &mut str) {
681-
// is_char_boundary checks that the index is in [0, .len()]
682-
if self.is_char_boundary(mid) {
683-
// SAFETY: just checked that `mid` is on a char boundary.
684-
unsafe { self.split_at_mut_unchecked(mid) }
685-
} else {
686-
slice_error_fail(self, 0, mid)
681+
match self.split_at_mut_checked(mid) {
682+
None => slice_error_fail(self, 0, mid),
683+
Some(pair) => pair,
687684
}
688685
}
689686

0 commit comments

Comments
 (0)