Skip to content

Add methods to split off array chunks from slices#150117

Open
JarredAllen wants to merge 1 commit intorust-lang:mainfrom
JarredAllen:slice-split-off-chunk
Open

Add methods to split off array chunks from slices#150117
JarredAllen wants to merge 1 commit intorust-lang:mainfrom
JarredAllen:slice-split-off-chunk

Conversation

@JarredAllen
Copy link
Contributor

@JarredAllen JarredAllen commented Dec 18, 2025

I implemented the slice methods described in my ACP rust-lang/libs-team#543:

impl<T> [T] {
    pub const fn split_off_first_chunk<'a, const N: usize>(self: &mut &'a Self) -> Option<&'a [T; N]>;
    pub const fn split_off_first_chunk_mut<'a, const N: usize>(self: &mut &'a mut Self) -> Option<&'a mut [T; N]>;
    pub const fn split_off_last_chunk<'a, const N: usize>(self: &mut &'a Self) -> Option<&'a [T; N]>;
    pub const fn split_off_last_chunk_mut<'a, const N: usize>(self: &mut &'a mut Self) -> Option<&'a mut [T; N]>;
}

The only difference from my original ACP post was that I put the first/last before chunk in the name instead of after it (the ACP has also been updated to match these names). My default intuition when I wrote that ACP was to have the names all appear next to each other alphabetically, but as I was implementing it I checked for similar-looking functions, and I found that split_first_chunk and related methods (which are basically these methods but without the in-place modification of self) do the other order and I decided it would be better to match how the other functions are named.

This is my first PR into rust itself, so I did my best to figure out the norms (both for the process around making a PR and the code I put in the PR) and follow them, but I probably got some stuff wrong so I'm sorry in advance for whatever I got wrong.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 18, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 18, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@tgross35 tgross35 added the S-waiting-on-ACP Status: PR has an ACP and is waiting for the ACP to complete. label Dec 20, 2025
@Mark-Simulacrum Mark-Simulacrum removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 28, 2025
@rust-bors

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Feb 2, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 2, 2026
@JarredAllen JarredAllen force-pushed the slice-split-off-chunk branch from 6542283 to 5db58a4 Compare February 2, 2026 18:36
@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-ACP Status: PR has an ACP and is waiting for the ACP to complete. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants