Change:
Feature gate: This is a tracking issue for the API. <!-- Include a short description of the feature. --<!-- For most library features, it'd be useful to include a summarized version of the public API. (E.g. just the public function signatures without their doc comments or implementation.) --2024-09-06: Most of this is stable now, except for the const-ness of the methods. Note that this mirrors the existing, already-stabilised API: <!-- For larger features, more steps might be involved. If the feature is changed later, please add those PRs here as well. --- [x] API change proposal (ACP)[^1]: rust-lang/libs-team [x] Implementation: [ ] Final comment period (FCP)[^2] [ ] Wait until is stable [ ] Stabilization PR <!-- Once the feature has gone through a few release cycles and there are no unresolved questions left, the feature might be ready for stabilization. If this feature didn't go through the RFC process, a final comment period (FCP) is always needed before stabilization. This works as follows: A library API team member can kick off the stabilization process, at which point the rfcbot will ask all the team members to verify they agree with stabilization. Once enough members agree and there are no concerns, the final comment period begins: this issue will be marked as such and will be listed in the next This Week in Rust newsletter. If no blocking concerns are raised in that period of 10 days, a stabilization PR can be opened by anyone. --<!-- Include any open questions that need to be answered before the feature can be stabilised. If multiple (unrelated) big questions come up, it can be a good idea to open a separate issue for each, to make it easier to keep track of the discussions. It's useful to link any relevant discussions and conclusions (whether on GitHub, Zulip, or the internals forum) here. --- [ ] Is this the best order for the tuple in ? Consistency with would have it be as was ACPed, but it might be confusing to have the two slice-like things in the opposite order from every other API I can think of that returns two subslices of the original. In , expected for , but for it to be in so the tuple is "in order", in some sense. ... [^1]: https://std-dev- [^2]: https://std-dev-
I have been yearning for better byte parsing with methods like these for a long time. So I jumped on trying out immediately. Was hoping it would greatly simplify parsing out fields of known lengths from buffers of serialized data. And it did! It did simplify a case of: + into just and I love this! Way less code, risk of indexing mistakes, and no unwraps/panics involved at all :sparkles: However, the lack of non-const-generic version of the same thing did bite me right after. It's really sad that is panicking and not returning . (This is being proposed in ) My experiment with this new API:
I'm a bit confused what you mean about there not being a const version of this API-- and co. are already const-unstable, and this method is also const-unstable. There is a bit going on with the various methods since they would rely on const traits (which are currently being removed to pave way for keyword generics), but at least those methods should work fine for you.
The features under this tracking issue are awesome. I approve. What I mean is there is no method to split a slice where the index is not const generic and it does not panic (split_at but without panic is what I want. But that's what the issue I linked to is about)
Note previous similar proposal: . Both currently are implemented, so I think one of them should be removed from codebase
The of this over the existing was "solv[ing] the -ness question" - I think should resolve that as well (while mostly keeping the same)?
I think this should be changed such that returns . This is not consistent specifically with but it is consistent with and other buffer splitting methods (, ). I think if you could ever rsplit more than one item that it would make more sense to return their natural order too, rather than reversing. Maybe we could justify that we want to be more consistent with and , and call the pop-like methods the special case?
This has been closed, but is still listed as the tracking issue for . But with constmutrefs in FCP, I think we can go ahead and stabilize constslicefirstlastchunk as well. :) Cc
fcp merge for these already-stable functions:
Team member has proposed to merge this. The next step is review by the rest of the tagged team members: [x] [x] [x] [ ] [ ] 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 for info about what commands tagged team members can give me.
:bell: This is now entering its final comment period, as per the . :bell:
The final comment period, with a disposition to merge, as per the , 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.

Discussion:
#![feature(const_size_of_val)] #![feature(const_size_of_val_raw)] #![feature(const_slice_from_ref)] <del> #![feature(const_slice_split_at_mut)] </del> #![feature(const_strict_overflow_ops)] #![feature(const_swap)] #![feature(const_try)]

/// ``` #[inline] #[stable(feature = "slice_first_last_chunk", since = "1.77.0")] <del> #[rustc_const_unstable(feature = "const_slice_first_last_chunk", issue = "111774")] </del> <ins> #[rustc_const_stable(feature = "const_slice_first_last_chunk", since = "CURRENT_RUSTC_VERSION")] #[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))] </ins> pub const fn first_chunk_mut<const N: usize>(&mut self) -> Option<&mut [T; N]> { if self.len() < N { None

/// ``` #[inline] #[stable(feature = "slice_first_last_chunk", since = "1.77.0")] <del> #[rustc_const_unstable(feature = "const_slice_first_last_chunk", issue = "111774")] </del> <ins> #[rustc_const_stable(feature = "const_slice_first_last_chunk", since = "CURRENT_RUSTC_VERSION")] #[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))] </ins> pub const fn split_first_chunk_mut<const N: usize>( &mut self, ) -> Option<(&mut [T; N], &mut [T])> {

/// ``` #[inline] #[stable(feature = "slice_first_last_chunk", since = "1.77.0")] <del> #[rustc_const_unstable(feature = "const_slice_first_last_chunk", issue = "111774")] </del> <ins> #[rustc_const_stable(feature = "const_slice_first_last_chunk", since = "CURRENT_RUSTC_VERSION")] #[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))] </ins> pub const fn split_last_chunk_mut<const N: usize>( &mut self, ) -> Option<(&mut [T], &mut [T; N])> {

/// ``` #[inline] #[stable(feature = "slice_first_last_chunk", since = "1.77.0")] <del> #[rustc_const_unstable(feature = "const_slice_first_last_chunk", issue = "111774")] </del> <ins> #[rustc_const_stable(feature = "const_slice_first_last_chunk", since = "CURRENT_RUSTC_VERSION")] #[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))] </ins> pub const fn last_chunk_mut<const N: usize>(&mut self) -> Option<&mut [T; N]> { if self.len() < N { None

#[inline] #[track_caller] #[must_use] <del> #[rustc_const_unstable(feature = "const_slice_split_at_mut", issue = "101804")] </del> <ins> #[rustc_const_stable(feature = "const_slice_split_at_mut", since = "CURRENT_RUSTC_VERSION")] #[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))] </ins> pub const fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) { match self.split_at_mut_checked(mid) { Some(pair) => pair,

/// assert_eq!(v, [1, 2, 3, 4, 5, 6]); /// ``` #[stable(feature = "slice_split_at_unchecked", since = "1.79.0")] <del> #[rustc_const_unstable(feature = "const_slice_split_at_mut", issue = "101804")] </del> <ins> #[rustc_const_stable(feature = "const_slice_split_at_mut", since = "CURRENT_RUSTC_VERSION")] #[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))] </ins> #[inline] #[must_use] pub const unsafe fn split_at_mut_unchecked(&mut self, mid: usize) -> (&mut [T], &mut [T]) {

/// assert_eq!(None, v.split_at_mut_checked(7)); /// ``` #[stable(feature = "split_at_checked", since = "1.80.0")] <del> #[rustc_const_unstable(feature = "const_slice_split_at_mut", issue = "101804")] </del> <ins> #[rustc_const_stable(feature = "const_slice_split_at_mut", since = "CURRENT_RUSTC_VERSION")] #[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))] </ins> #[inline] #[must_use] pub const fn split_at_mut_checked(&mut self, mid: usize) -> Option<(&mut [T], &mut [T])> {