Is there a way to declare an uninitialised slice(i.e MaybeUninit<[T]>
)?
I know I could use [MaybeUninit<T>]
except A, it doesn't accurately describe the data structure(an uninitialised slice of T
s, not a slice of uninitialised T
s) and B, I would have to duplicate all of my existing code that uses &[mut] MaybeUninit<T:?Sized>
so that it works for
&[mut] [MaybeUninit<T:?Sized>]
.
Well, not a slice per se, because the type parameter must be Sized
. But you can have a MaybeUninit<[T; N]>
, i.e., and uninitialized array.
A MaybeUninit<[T]>
would be a slice that's either completely initialized or not at all.
If you're initializing it all at once, you can just use [MaybeUninit<T>]
and transmute it to a [T]
when you need to pass it your other code[1].
-
assuming the initialization is done, obviously âŠī¸
1 Like
I think that should work. Thanks.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.