Add array transpose From implementations: [MaybeUninit<T>; N]
<-> MaybeUninit<[T; N]>
#110
Labels
ACP-accepted
API Change Proposal is accepted (seconded with no objections)
api-change-proposal
A proposal to add or alter unstable APIs in the standard libraries
T-libs-api
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: