Crates.io | autopad |
lib.rs | autopad |
version | 1.0.0 |
source | src |
created_at | 2023-02-24 04:20:57.79257 |
updated_at | 2023-02-24 04:20:57.79257 |
description | Define structs with offset fields |
homepage | |
repository | https://github.com/antangelo/autopad |
max_upload_size | |
id | 793305 |
size | 24,728 |
Adds the autopad!
proc macro, allowing for structs to be defined with fields at specified offsets.
autopad!(
#[repr(C)] // Needed to preserve field orders
struct WithPadding {
root: u8, // At offset 0x0
0x100 => partway_in: u32,
after_offset: u32, // At 0x104
0x200 => final_field: u8,
}
);
The macro will fill the struct with appropriate padding arrays such that each field is properly offset in the result.
The intended use case for this is for structs that represent MMIO devices with sparsely allocated or large gaps between registers.
repr(Rust)
repr(C)
or another repr that maintains orderingpad_struct!
will only accept one struct definitionstruct Named { x: i32, y: i32 }
, not struct Unnamed(i32, i32);
)Some of these are fixable, PRs are welcome.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.