You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This enables full field reference projection for fields that are sufficiently aligned and field read/write access for all fields and subfields. This must be done through direct struct field access for the compiler to accept it.
Sample use case
Say the input buffer you receive has bytes in the format of BigStruct, and our function reads specific fields out of those bytes based on a struct layout defined by bindgen. There are too many unread fields to reasonably copy it. However, the input buffer may be unaligned. So, you first access the prefix as a &Unalign<BigStruct>.
In order to access specific unaligned fields safely, you need one of the following:
Currently, the workaround is to declare your own repr(packed) newtype that has an accessible inner value. But honestly, I should be able to use the built-in Unalign newtype for this. Rust will guard against an accidental reference to an unaligned field.
The text was updated successfully, but these errors were encountered:
kupiakos
changed the title
Make the value in Unalign public
Expose the inner value of Unalign as public
Oct 10, 2024
It might be worth gating the inner pub field based on Rust version since the lint producing a hard error for referencing an underaligned field was introduced in 1.69.
Additionally, if we add T: ?Sized to Unalign, then only in 1.76 was this lint fixed for unsized fields.
This enables full field reference projection for fields that are sufficiently aligned and field read/write access for all fields and subfields. This must be done through direct struct field access for the compiler to accept it.
Sample use case
Say the input buffer you receive has bytes in the format of
BigStruct
, and our function reads specific fields out of those bytes based on a struct layout defined by bindgen. There are too many unread fields to reasonably copy it. However, the input buffer may be unaligned. So, you first access the prefix as a&Unalign<BigStruct>
.In order to access specific unaligned fields safely, you need one of the following:
unsafe
Unalign
.Currently, the workaround is to declare your own
repr(packed)
newtype that has an accessible inner value. But honestly, I should be able to use the built-inUnalign
newtype for this. Rust will guard against an accidental reference to an unaligned field.The text was updated successfully, but these errors were encountered: