-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
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_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
tgross35, IndigoLily, notriddle, faern and sffcfaern, teor2345 and KarstenB
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.