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
Unresolved Questions
Name of the methods. Some possibilities (suggested in ACP discussion):
split_at_checked and split_at_mut_checked — follows naming of split_at_unchecked and split_at_mut_unchecked. Using suffix makes the names sort nicely together.
checked_split_at and checked_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 and try_split_at_mut — follows naming of various fallible methods such as try_from, try_new, try_for_each etc. Shortest of the three suggestions.
Feature gate:
#![feature(split_at_checked)].This is a tracking issue for the addition of
split_at_checkedandsplit_at_mut_checkedmethods to[T]andstrtypes which are non-panicking versions ofsplit_atandsplit_at_mutmethods. Rather than panicking when spit index is out of range (likesplit_atdoes), the methods returnNone.Public API
Steps / History
Unresolved Questions
Name of the methods. Some possibilities (suggested in ACP discussion):
split_at_checkedandsplit_at_mut_checked— follows naming ofsplit_at_uncheckedandsplit_at_mut_unchecked. Using suffix makes the names sort nicely together.checked_split_atandchecked_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_atandtry_split_at_mut— follows naming of various fallible methods such astry_from,try_new,try_for_eachetc. Shortest of the three suggestions.Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩