reinerp / varlen-rs

Ergonomic variable-length types in Rust
BSD 3-Clause "New" or "Revised" License
7 stars 1 forks source link

Advanced repr support #1

Closed CraftSpider closed 2 years ago

CraftSpider commented 2 years ago

Currently, it's noted that fixed-length fields in a define_varlen will always be laid out 'as the Rust compiler decides'. It would be nice if the crate could support repr(C) or similar, to allow defining structs that have a portable layout, or even are explicitly compatible with C variable-size end arrays.

Note: If #[repr(C)] on a struct works as-is, it would at least be nice to have documentation of this fact.

reinerp commented 2 years ago

This is actually supported already, but this support was not documented. If you specify attributes on your struct, they will be applied to the underlying struct definition. This includes the #[repr(C)] attribute.

Commit ae73d7fef973877ce60d1f4035f43a29d581d9ca adds a test and updates the documentation that this is supported.