Repository navigation
Tracking Issue for slice::array_chunks #74985
Copy link
Copy link
Closed as not planned
Labels
A-arrayArea: `[T; N]`Area: `[T; N]`A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-sliceArea: `[T]`Area: `[T]`C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-generic_const_exprs`#![feature(generic_const_exprs)]``#![feature(generic_const_exprs)]`I-libs-radarLibs issues that are tracked on the team's radar.Libs issues that are tracked on the team's radar.P-lowLow priorityLow priorityT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]
Description
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
-
RestrictMakeNto values greater than 0 at compile time instead of using a runtime panic.<[T]>::array_*methods fail to compile on 0 len arrays #99471 - Support calls where
N == 0is unreachable due to conditionals Tracking Issue for slice::array_chunks #74985 (comment)- It was decided that a runtime panic is appropriate: Tracking Issue for slice::array_chunks #74985 (comment)
- Adjust documentation (see instructions on rustc-dev-guide)
- Stabilization PR (see instructions on rustc-dev-guide)
- slice_as_chunks: Stabilize
slice_as_chunkslibrary feature #139656 - array_chunks
- slice_as_chunks: Stabilize
Unresolved Questions
- Iterator vs slices, Does
[T]::array_chunksreally need to be an iterator? #76354
Implementation history
- implemented in add
slice::array_chunksto std #74373 - mut version in Add
slice::array_chunks_mut#75021 as_chunks{_mut}in Add [T]::as_chunks(_mut) #76635as_rchunks{_mut}and unchecked versions in Addas_rchunks(and friends) to slices #78818- const
as_(r)chunkin constifyslice_as_chunks(unstable) #111453 - Stabilize
slice_as_chunkslibrary feature #139656
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-arrayArea: `[T; N]`Area: `[T; N]`A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-sliceArea: `[T]`Area: `[T]`C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-generic_const_exprs`#![feature(generic_const_exprs)]``#![feature(generic_const_exprs)]`I-libs-radarLibs issues that are tracked on the team's radar.Libs issues that are tracked on the team's radar.P-lowLow priorityLow priorityT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]
Activity
Auto merge of rust-lang#75021 - cuviper:array_chunks_mut, r=scottmcm
Rollup merge of rust-lang#75026 - JulianKnodt:array_windows, r=Amanieu
Rollup merge of rust-lang#76635 - scottmcm:slice-as-chunks, r=LukasKa…
joshlf commentedon Feb 10, 2021
Is there any intention of providing the reverse versions of these functions?
thomcc commentedon Apr 25, 2021
What would that look like?
joshlf commentedon Apr 26, 2021
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.
newpavlov commentedon Apr 26, 2021
@joshlf
Both slice of arrays and custom iterator type would implement the
DoubleEndedIterator, so your use case does not need a separate reverse method.joshlf commentedon Apr 26, 2021
That's only true if
Nevenly divides the length of the slice (seearray_chunksdocs). Otherwise, the remaining elements are only accessible via theremaindermethod, and won't be iterated over in theDoubleEndedIteratorimplementation.161 remaining items
scottmcm commentedon Jul 2, 2025
There's a nice version of that in the "remove
array_chunks" PR above too:So if there's no tail expected -- there's a bug somewhere if it happens -- then something like
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_chunksiterator in addition to the already-stable stuff.)fintelia commentedon Jul 2, 2025
There's a case to be made that
as_chuncks_exactshould be added as shorthand for that. But I could also see not wanting to add all the combinationsbriansmith commentedon Jul 2, 2025
This doesn't work well with coverage reporting, currently: #143149.
This is what I do, having
as_chunks_exactreturn anOption<&[[T; N]]>until the coverage stuff is fixed, so that I can use.unwrap_or_else(|| unreachable!())instead ofelse { unreachable!() }.As well as maybe a long debate on whether it should return
Option<>or panic.Kixunil commentedon Jul 3, 2025
as_chunks_exactwould be nice to have if it returnedResultwhere the error type contains the length of the trailing slice (preferably asNonZeroUsize). BecauseOptionhas the concise alternative @scottmcm suggested but if one wants to returnResultwith the information it requires one more line of code.Rollup merge of rust-lang#143289 - scottmcm:remove-array-chunks, r=jh…
Rollup merge of rust-lang#143289 - scottmcm:remove-array-chunks, r=jh…
Auto merge of #143289 - scottmcm:remove-array-chunks, r=jhpratt
Auto merge of rust-lang#143289 - scottmcm:remove-array-chunks, r=jhpratt
Auto merge of #143289 - scottmcm:remove-array-chunks, r=jhpratt
Auto merge of #143289 - scottmcm:remove-array-chunks, r=jhpratt
Auto merge of #143289 - scottmcm:remove-array-chunks, r=jhpratt
Auto merge of #143289 - scottmcm:remove-array-chunks, r=jhpratt
Auto merge of #143289 - scottmcm:remove-array-chunks, r=jhpratt