-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add array transpose From implementations: [MaybeUninit<T>; N]
<-> MaybeUninit<[T; N]>
#110
Comments
I think this is a good idea. The other reason this is superior to |
On further though, I wonder if just a |
Been going back and forth on this and I think you're right. Also after seeing rust-lang/rust#48711, I'm now properly scared: if we later decide the From impls are bad we're screwed, whereas adding |
Problem statement
The primary use case for
MaybeUninit
is to initialize arrays of stuff (typically u8s). This is currently poorly supported, requiring the user to enable unstable features (e.g.uninit_array
) or immediately mark an array asassume_init
which is very confusing to beginners.Motivation, use-cases
UH_OH can be replaced with a
transmute
(Requires unsafe. Also is that actually safe? It is, but no one wants to spend hours digging around to figure that out.) or witharray_assume_init
(Requires nightly).Having a
From
implementation between[MaybeUninit<T>; N]
andMaybeUninit<[T; N]>
makes it easy to move between filling an uninitialized array and then marking it as initialized.Solution sketches
See rust-lang/rust#102023
Links and related work
rust-lang/rust#88837
Other proposals have suggested implementing
Index{,Mut}
. While I think that's probably a slightly nicer API in its limited scope, users are very quickly going to be sad when they see that their favoriteMaybeUninit
method isn't available on[MaybeUninit<T>; N]
. Eventually that will lead to API duplication as[MaybeUninit<T>; N]
methods are added to mirror theMaybeUninit
ones.[MaybeUninit<T>; N]
<->MaybeUninit<[T; N]>
conversion avoids this entirely.The text was updated successfully, but these errors were encountered: