Skip to content

Commit 43453a8

Browse files
committed
Don't panic in ceil_char_boundary
1 parent e94bda3 commit 43453a8

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

library/core/src/str/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,13 @@ impl str {
271271

272272
/// Finds the closest `x` not below `index` where `is_char_boundary(x)` is `true`.
273273
///
274+
/// If `x` is greater than the length of the string, this returns the length of the string.
275+
///
274276
/// This method is the natural complement to [`floor_char_boundary`]. See that method
275277
/// for more details.
276278
///
277279
/// [`floor_char_boundary`]: str::floor_char_boundary
278280
///
279-
/// # Panics
280-
///
281-
/// Panics if `index > self.len()`.
282281
///
283282
/// # Examples
284283
///
@@ -296,7 +295,7 @@ impl str {
296295
#[inline]
297296
pub fn ceil_char_boundary(&self, index: usize) -> usize {
298297
if index > self.len() {
299-
slice_error_fail(self, index, index)
298+
self.len()
300299
} else {
301300
let upper_bound = Ord::min(index + 4, self.len());
302301
self.as_bytes()[index..upper_bound]

0 commit comments

Comments
 (0)