4 ms·
They mean whether the value is properly initialized, as in all the bytes that make up that value have set values that are valid for that type. For example, in R
by Measter 2y ago
They mean whether the value is properly initialized, as in all the bytes that make up that value have set values that are valid for that type. For example, in Rust the only valid values a boolean can have are 0 and 1, anything else is invalid. Notably, in the abstract machine, bytes actually have 257 values: 0-255 and uninitialized. Uninitialized means that an initialized value was never written to it. Reading a value that is not properly initialized is undefined behaviour, and optimization passes can result in unpredictable changes in behaviour of the code.
The type they mentioned is MaybeUninit (https://doc.rust-lang.org/std/mem/union.MaybeUninit.html https://doc.rust-lang.org/std/mem/union.MaybeUninit.html), which is used to represent values that are not fully initialized. It's worth reading the documentation for that type.
- saghm 2y agoAh, I see. Since I don't touch unsafe Rust very much at all, I completely forgot about this type. It makes sense that having a "safe" way of dealing with this would be useful, especially for a "C++ successor" language.