-
Couldn't load subscription status.
- Fork 13.9k
Closed as not planned
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
These function:
Are inconvenient to use, one need to check len (or be sure) then call split_at() that will also check len, first this can lead to bad asm #74938 & #30112. Then it's inelegant. This would be ok if these function would be unsafe, so not checking the len twice.
These function are better cause there return an Option:
I propose we add the equivalent of split_at returning a Result
impl slice {
fn split_at_mid(&self, mid: usize) -> Result<(&[T], &[T]), usize>;
fn split_at_mid_mut(&mut self, mid: usize) -> Result<(&mut [T], &mut [T]), usize>;
}
impl str {
fn split_at_mid(&self, mid: usize) -> Result<(&str, &str), usize>;
fn split_at_mid_mut(&mut self, mid: usize) -> Result<(&mut str, &mut str), usize>;
}The Err be mid or len (but we could imagine more precise error for example str could indicate char error boundary) or we keep it simple with Option
BTW: We miss split_first() and split_last() on str.
sanmai-NL, SadiinsoSnowfall, gauteh, zsluedem, kamulos and 10 more
Metadata
Metadata
Assignees
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.