Skip to content

Tracking Issue for slice::array_chunks #74985

Closed as not planned
Closed as not planned

Description

@lcnr

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

  1. 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-api[DEPRECATED; DO NOT USE]
    on Jul 31, 2020
  2. added
    I-libs-radarLibs issues that are tracked on the team's radar.
    on Aug 6, 2020
  3. added a commit that references this issue on Sep 12, 2020
  4. added a commit that references this issue on Sep 16, 2020
  5. added a commit that references this issue on Oct 26, 2020
  6. joshlf commented on Feb 10, 2021

    @joshlf
    Contributor

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

  7. thomcc commented on Apr 25, 2021

    @thomcc
    Member

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

    What would that look like?

  8. joshlf commented on Apr 26, 2021

    @joshlf
    Contributor

    Same API, but iterating backwards. I have a use case in which I need to convert either a prefix or a suffix of a slice to an array reference. This API is perfect for the prefix use case, and I'd love to be able to use it for the suffix use case as well.

  9. newpavlov commented on Apr 26, 2021

    @newpavlov
    Contributor

    @joshlf
    Both slice of arrays and custom iterator type would implement the DoubleEndedIterator, so your use case does not need a separate reverse method.

  10. joshlf commented on Apr 26, 2021

    @joshlf
    Contributor

    That's only true if N evenly divides the length of the slice (see array_chunks docs). Otherwise, the remaining elements are only accessible via the remainder method, and won't be iterated over in the DoubleEndedIterator implementation.

  11. 161 remaining items

  12. 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.)

  13. 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

  14. 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.

  15. 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.

  16. added a commit that references this issue on Jul 27, 2025
  17. added a commit that references this issue on Jul 28, 2025
  18. added a commit that references this issue on Jul 29, 2025
  19. 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)]`I-libs-radarLibs issues that are tracked on the team's radar.P-lowLow priorityT-libs-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions