Skip to content

Tracking Issue for slice::array_chunks #74985

@lcnr

Description

@lcnr
Contributor

The feature gate for the issue is #![feature(array_chunks)].

Also tracks as_(r)chunks(_mut) in #![feature(slice_as_chunks)] -- these were FCPed starting at #74985 (comment) below.

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also uses as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps

Unresolved Questions

Implementation history

Activity

added
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
A-const-genericsArea: const generics (parameters and arguments)
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
on Jul 31, 2020
added
Libs-TrackedLibs issues that are tracked on the team's project board.
on Aug 6, 2020
added a commit that references this issue on Sep 12, 2020
added a commit that references this issue on Sep 16, 2020
23a6777
added a commit that references this issue on Oct 26, 2020
13e88d6
joshlf

joshlf commented on Feb 10, 2021

@joshlf
Contributor

Is there any intention of providing the reverse versions of these functions?

194 remaining items

scottmcm

scottmcm commented on Jul 2, 2025

@scottmcm
Member

There's a nice version of that in the "remove array_chunks" PR above too:

-        if v.len() % 2 != 0 {
+        let (chunks, []) = v.as_chunks::<2>() else {
             return Err(FromUtf16Error(()));
-        }
+        };

So if there's no tail expected -- there's a bug somewhere if it happens -- then something like

let (rgba, []) = data.as_chunks() else { unreachable!() };

might be a nice (and fuzzable!) way to communicate and catch that expectation.

(And yes, this is a fine place for this conversation because it's in context of whether there's sufficient value in the array_chunks iterator in addition to the already-stable stuff.)

fintelia

fintelia commented on Jul 2, 2025

@fintelia
Contributor

There's a case to be made that as_chuncks_exact should be added as shorthand for that. But I could also see not wanting to add all the combinations

briansmith

briansmith commented on Jul 2, 2025

@briansmith
Contributor

let (rgba, []) = data.as_chunks() else { unreachable!() };

This doesn't work well with coverage reporting, currently: #143149.

There's a case to be made that as_chuncks_exact should be added as shorthand for that.

This is what I do, having as_chunks_exact return an Option<&[[T; N]]> until the coverage stuff is fixed, so that I can use .unwrap_or_else(|| unreachable!()) instead of else { unreachable!() }.

But I could also see not wanting to add all the combinations

As well as maybe a long debate on whether it should return Option<> or panic.

Kixunil

Kixunil commented on Jul 3, 2025

@Kixunil
Contributor

as_chunks_exact would be nice to have if it returned Result where the error type contains the length of the trailing slice (preferably as NonZeroUsize). Because Option has the concise alternative @scottmcm suggested but if one wants to return Result with the information it requires one more line of code.

added a commit that references this issue on Jul 27, 2025
added a commit that references this issue on Jul 28, 2025
added a commit that references this issue on Jul 29, 2025
added a commit that references this issue on Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-arrayArea: `[T; N]`A-const-genericsArea: const generics (parameters and arguments)A-sliceArea: `[T]`C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-generic_const_exprs`#![feature(generic_const_exprs)]`Libs-TrackedLibs issues that are tracked on the team's project board.P-lowLow priorityT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @briansmith@mina86@cuviper@shepmaster@Amanieu

      Issue actions

        Tracking Issue for slice::array_chunks · Issue #74985 · rust-lang/rust