-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Does [T]::array_chunks really need to be an iterator? #76354
Copy link
Copy link
Closed
Labels
A-arrayArea: `[T; N]`Area: `[T; N]`B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-arrayArea: `[T; N]`Area: `[T; N]`B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
After bit after reviewing the code in #75021 I had a thought: if this iterator is mostly just a wrapper on a slice iterator, does it even need to be an iterator at all?
The original
.chunks()call does (as does.windows), because the slices it wants to return don't exist anywhere.But the arrays returned by
array_chunksare inline in the original slice allocation, so the API could just return the slice that the method is already creating, instead of hiding it in an iterator.To be more concrete:
Not only would this be more general (the
ArrayChunkstype doesn't currently expose the slice), but I think it would make it less likely that people would forget to correctly handle the.remainder(). (While still being easy to ignore it with.0if they insist.) And returning tuples like this has precedent withsplit_*andalign_toand such. (Many other names could work too, like.as_chunks(_mut).)Also, such a method would be nice to have as the inverse of a hypothetical
flatten: &[[T; N]] -> &[T]. (EDIT: No longer as hypothetical, #95629.)array_chunkstracking issue #74985