Closed as not planned
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
.