Description
This recently posted article makes that point that, because the default representation makes no guarantees of data layout, one must use write_unaligned
to write to the fields of a struct when initializing it field by field.
This runs contrary to the the documentation of MaybeUninit
about initializing a struct field by field, and also to what the nomicon has to say on the subject:
By default, composite structures have an alignment equal to the maximum of their fields' alignments. Rust will consequently insert padding where necessary to ensure that all fields are properly aligned and that the overall type's size is a multiple of its alignment.
Should we amend the reference to either link to the nomicon for more details, or to specify that fields that can be accessed in a struct are properly aligned (no write_unaligned
necessary)?