Im unsure what the difference between a
MaybeUninit<[T; N]> and a
[MaybeUninit<T>; N] is.
What I understand is that the latter is preferred when dealing with partial arrays, however the ArrayVec crate uses the former, but also deals with partial arrays. (https://github.com/bluss/arrayvec/blob/master/src/lib.rs#L95)
And, is this okey to do?:
let mut array: MaybeUninit<[T; 10]> = MaybeUninit::uninit(); let ptr: *mut T = array.as_mut_ptr() as *mut T // <--- cast to *mut T, since the ptr() method gives *mut [T; 10] ptr.write(some_value)
Notice the array within the MaybeUninit is never really initialized, but is still written to.
Im unsure what the difference between a MaybeUninit<[T; N]> and a [MaybeUninit<T>; N] is.
Good question! There isn't really any.
If we had const generics, we might want to add methods to freely convert between the two.
transmuting between the two is okay for any
And, is this okey to do?
ptr.write on uninitialized memory is okay. having to do a raw ptr cast is not nice (IMO those should be frowned upon as much as
transmute), but cannot always be avoided with our current APIs.