I am using serde to save and load a struct that has an array that may or may not be initialised.
#[repr(C)]
pub struct MyStruct {
array: [MaybeUninit<f32>; 3],
is_initialized: bool,
}
The way I save it is by transmuting it to a struct that has the same layout but isn't MaybeUninit:
#[derive(Serialize, Deserialize)]
#[repr(C)]
struct Intermediary {
array: [f32; 3],
is_initialized: bool,
}
This Intermediary struct I can save and load easily. When I do this miri complains for accessing uninitialised memory (rightly so).
The only way to access the array from outside my library is through functions that make sure that the array is initialised. What exactly can go wrong if I do this?