Closed
Description
Feature gate: #![feature(split_at_checked)]
.
This is a tracking issue for the addition of split_at_checked
and split_at_mut_checked
methods to [T]
and str
types which are non-panicking versions of split_at
and split_at_mut
methods. Rather than panicking when spit index is out of range (like split_at
does), the methods return None
.
Public API
impl<T> [T] {
pub fn split_at_checked(&self, mid: usize) -> Option<(&[T], &[T])>;
pub fn split_at_mut_checked(&self, mid: usize) -> Option<(&[T], &[T])>;
}
impl str {
pub fn split_at_checked(&self, mid: usize) -> Option<(&str, &str)>;
pub fn split_at_mut_checked(&mut self, mid: usize) -> Option<(&str, &str)>;
}
Steps / History
- ACP: ACP: Introduce checked_split_at{,_mut} methods libs-team#308
- Implementation: core: introduce split_at{,_mut}_checked #118578
- Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
Name of the methods. Some possibilities (suggested in ACP discussion):
split_at_checked
andsplit_at_mut_checked
— follows naming ofsplit_at_unchecked
andsplit_at_mut_unchecked
. Using suffix makes the names sort nicely together.checked_split_at
andchecked_split_at_mut
— follows naming convention of arithmetic types (e.g.checked_add
). Those new functions serve similar purpose as checked arithmetic operations.try_split_at
andtry_split_at_mut
— follows naming of various fallible methods such astry_from
,try_new
,try_for_each
etc. Shortest of the three suggestions.