Description
According to the reference, #[repr(packed)]
does not guarantee field order.
Inter-field padding is guaranteed to be the minimum required in order to satisfy each field's (possibly altered) alignment (although note that, on its own,
packed
does not provide any guarantee about field ordering). An important consequence of these rules is that a type with#[repr(packed(1))]
(or#[repr(packed)])
will have no inter-field padding.
As a consequence, I suspect that the definition of TupleNULE
isn’t guaranteed to be correct, as the linked validate_byte_slice
implementation appears to assume the field order.
I haven’t checked whether the same assumption is used in other places, or how the documentation or ULE
should perhaps be updated not to recommend #[repr(packed)]
too lightheartedly.
For TupleNULE
, I’m not sure I understand the need for packed
anyway, as the components are required to be ULE
, too. A #[repr(C)]
should work fine and give every guarantee necessary, right? (I haven’t checked or tested whether #[repr(C)]
and #[repr(packed)]
can be combined; if they can, that sounds like a good contender, too.)