padding-struct
A Rust procedural macro for automatically adding explicit padding fields to #[repr(C)] structs.
Overview
When working with #[repr(C)] structs,
the Rust compiler automatically adds padding bytes to ensure proper alignment.
The #[padding_struct] macro makes these padding bytes explicit
by automatically generating padding fields in your struct definitions.
Basic Example
use padding_struct;
The macro generates a new struct with explicit paddings:
// Padded struct (the one you'll use)
Integration with zerocopy
The generated structs work seamlessly with zerocopy for safe transmutation:
use padding_struct;
use *;
// Now you can safely cast to/from bytes
let s = new_zeroed;
let bytes: & = s.as_bytes;
assert_eq!;
assert_eq!;
License
This project is licensed under MPL-2.0.