Skip to content
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 and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking Issue for additional array::IntoIter constructors (feature array_into_iter_constructors) #91583

Open
1 of 6 tasks
scottmcm opened this issue Dec 6, 2021 · 2 comments
Labels
A-array Area: [T; N] C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@scottmcm
Copy link
Member

scottmcm commented Dec 6, 2021

Feature gate: #![feature(array_into_iter_constructors)]

This is a tracking issue for the from_raw_partsnew_unchecked and empty constructors on core::array::IntoIter.

This allows creating such an iterator with something other than a fully-initialized array.

Public API

// core::array

impl<T, const N: usize> IntoIter<T, N> {
    pub const fn empty() -> Self;
    pub const unsafe fn new_unchecked(buffer: [MaybeUninit<T>; N], initialized: Range<usize>) -> Self;
}

Steps / History

Unresolved Questions

  • Should this be named from_raw_parts or something else?
  • Should this have to go through an ArrayVec-like type (like how Vec has from_raw_parts instead of vec::IntoIter having it), instead of making the IntoIter directly?
  • What's a good name for new_unchecked? It was previously from_raw_parts, but was changed at reviewer request in the initial PR. Then after that, new was deprecated, which makes me feel like new_unchecked is a bit odd too.
@scottmcm scottmcm added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. labels Dec 6, 2021
@scottmcm
Copy link
Member Author

scottmcm commented Feb 3, 2023

Hmm, I noticed today that these methods are, arguably, pessimizing the array iterator slightly. new gives it a valid array, so it could be using ManuallyDrop instead of MaybeUninit.

Does that actually matter? Dunno. But it's a foundational difference between an array builder and an array drainer.

@workingjubilee workingjubilee added the A-array Area: [T; N] label Mar 7, 2023
@clarfonthey
Copy link
Contributor

I would definitely like to see an implementation of Default for IntoIter that uses empty(), although that would be insta-stable and require an FCP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-array Area: [T; N] C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants