Add Vec::into_chunks by ashivaram23 · Pull Request #142138 · rust-lang/rust (original) (raw)

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation7 Commits4 Checks9 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

@ashivaram23

@ashivaram23

@rustbot

r? @thomcc

rustbot has assigned @thomcc.
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

@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

Jun 7, 2025

@rust-log-analyzer

This comment has been minimized.

@ashivaram23

@rust-log-analyzer

This comment has been minimized.

@ashivaram23

lukaslueg

#[unstable(feature = "vec_into_chunks", issue = "142137")]
pub fn into_chunks<const N: usize>(mut self) -> Vec<[T; N], A> {
const {
assert!(N != 0, "chunk size should be greater than zero");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

language nit: "must be" instead of "should be", as this is not an advisory suggestion.

@ashivaram23

scottmcm

Comment on lines +3036 to +3044

let len_remainder = len % N;
if len_remainder != 0 {
self.truncate(len - len_remainder);
}
let cap_remainder = cap % N;
if !T::IS_ZST && cap_remainder != 0 {
self.buf.shrink_to_fit(cap - cap_remainder);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was debating whether the != 0 checks here are useful, since the methods called will immediately do similar checks, but I think I ended up at 🤷 might as well leave it as-is.

@scottmcm

I'm personally unsure about whether the infallible-but-possible-reallocating version is the right thing to do for this API, but it matches the ACP so that sounds like a tracking issue problem, not a this-PR problem.

Code change itself looks good to me, so
@bors r+ rollup
r? scottmcm

@bors

📌 Commit c1d32d8 has been approved by scottmcm

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Jul 1, 2025

jhpratt added a commit to jhpratt/rust that referenced this pull request

Jul 1, 2025

@jhpratt

bors added a commit that referenced this pull request

Jul 2, 2025

@bors

Rollup of 12 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

jhpratt added a commit to jhpratt/rust that referenced this pull request

Jul 2, 2025

@jhpratt

bors added a commit that referenced this pull request

Jul 2, 2025

@bors

Rollup of 11 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

jhpratt added a commit to jhpratt/rust that referenced this pull request

Jul 2, 2025

@jhpratt

bors added a commit that referenced this pull request

Jul 2, 2025

@bors

Rollup of 12 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Jul 2, 2025

@matthiaskrgr

bors added a commit that referenced this pull request

Jul 2, 2025

@bors

Rollup of 11 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Jul 2, 2025

@matthiaskrgr

bors added a commit that referenced this pull request

Jul 2, 2025

@bors

Rollup of 10 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

bors added a commit that referenced this pull request

Jul 2, 2025

@bors

Rollup of 9 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

rust-timer added a commit that referenced this pull request

Jul 2, 2025

@rust-timer

Rollup merge of #142138 - ashivaram23:vec_into_chunks, r=scottmcm

Add Vec::into_chunks

Tracking issue #142137

github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request

Jul 11, 2025

@matthiaskrgr

Labels

S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

T-libs

Relevant to the library team, which will review and decide on the PR/issue.