5 ms·
I don't understand the reaction. > By default, composite structures have an alignment equal to the maximum of their fields' alignments. Rust will consequently
by PartiallyTyped 3y ago
I don't understand the reaction.
> 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. [...]
> There is no indirection for these types; all data is stored within the struct, as you would expect in C. However with the exception of arrays (which are densely packed and in-order), the layout of data is not specified by default.
struct A {
a: i32,
b: u64,
}
struct B {
a: i32,
b: u64,
}
> Rust does guarantee that two instances of A have their data laid out in exactly the same way. However Rust does not currently guarantee that an instance of A has the same field ordering or padding as an instance of B.
Here is my source: https://doc.rust-lang.org/nomicon/repr-rust.html https://doc.rust-lang.org/nomicon/repr-rust.html