Hacker News new | ask | show | jobs
by TheCycoONE 1604 days ago
They are pretty useful for a number of data structures, and Rust uses them heavily in the standard library.

I'm not aware of as many uses of field by field initialization of a struct but there is an example similar to this blog in the docs[1] (without the alignment considerations.)

That said my read has been the complexity is accidental as a result of language decisions to improve safe rust. MaybeUnit was only defined 3 years ago when it was discovered that mem::uninitialized /zeroed resulted in undefined behavior when used with bools. [2][3]

[1] https://doc.rust-lang.org/std/mem/union.MaybeUninit.html#ini...

[2] https://github.com/rust-lang/rust/issues/53491

[3] https://doc.rust-lang.org/std/mem/fn.uninitialized.html