Repository navigation
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-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]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
Reacted by Trevor Gross, Lily, Michael Howell, Linus Färnstrand and Shane F. Carr
Reacted by Linus Färnstrand, teor and Karsten Becker
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-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Activity
tgross35 commentedon Jan 10, 2024
I wonder if the
strmethod should return aResultsince they have two failure modes - invalid char boundary and OOB of the string.mina86 commentedon Jan 10, 2024
Personally I’d rather not complicate the interface and have the methods on slice and on str return the same kind of value. No strong feelings though.
Auto merge of rust-lang#118578 - mina86:c, r=dtolnay
Rollup merge of rust-lang#118578 - mina86:c, r=dtolnay
Rollup merge of rust-lang#118578 - mina86:c, r=dtolnay
Rollup merge of rust-lang#118578 - mina86:c, r=dtolnay
Unrolled build for rust-lang#118578
faern commentedon Feb 20, 2024
Thanks for pushing for this feature ❤️ I really want this to land! Panic free handling of byte slices has been in a pretty bad state a long time. I came here just now because I was trying out the new
split_first_chunkjust to realize I could not make the code improvements I have been wanting a long time without also having panic free slice splitting with a runtimemid.split_first_chunkandsplit_at_checkeddo the same thing really, but one of them have the splitting index as a const generic.I just tried
slice::split_first_chunkand it does wonders to my code. Both in terms of code simplicity/readability but also to amount of potentially panic locations.@mina86 You can check the implementation PR step in your initial comment. That's merged 🥳
UserIsntAvailable commentedon Apr 22, 2024
@m-ou-se Can we get a fcp for this?
slice::split_at_{mut}_uncheckedis getting stabilized on1.79.0and I think is going to be kinda akward to not also provide the safe non-panic option as well on the same release.Thanks in advance.
For consistency with the existing methods on
sliceandstr, it probably should be calledsplit_at_{mut}_checked.IMO returning option here should be fine. But
t-libsmight have something else to say about this?Amanieu commentedon Apr 23, 2024
We discussed this in the libs-api meeting and are happy to merge this as it is. The
_checkedsuffix is consistent with the already stabilized_uncheckedmethods, and returning anOptionis consistent with the.get()method.@rfcbot fcp merge
rfcbot commentedon Apr 23, 2024
Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members:
No concerns currently listed.
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
See this document for info about what commands tagged team members can give me.
7 remaining items
rfcbot commentedon May 3, 2024
The final comment period, with a disposition to merge, as per the review above, is now complete.
As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.
This will be merged soon.
Rollup merge of rust-lang#124678 - UserIsntAvailable:feat/stabilize-s…
Rollup merge of rust-lang#124678 - UserIsntAvailable:feat/stabilize-s…
Unrolled build for rust-lang#124678
Stargateur commentedon Oct 11, 2024
this was duplicate of #90410. I would have prefer Result.
This become stable very fast Oo. (nice)
rust: transmute: simplify code with Rust 1.80.0 `split_at_*checked()`
rust: transmute: simplify code with Rust 1.80.0 `split_at_*checked()`
rust: transmute: simplify code with Rust 1.80.0 `split_at_*checked()`
rust: transmute: simplify code with Rust 1.80.0 `split_at_*checked()`
rust: transmute: simplify code with Rust 1.80.0 `split_at_*checked()`
rust: transmute: simplify code with Rust 1.80.0 `split_at_*checked()`