6 stable releases
| 2.0.0 | Jul 3, 2024 |
|---|---|
| 1.2.0 | Jun 20, 2024 |
| 1.1.1 | Jun 20, 2024 |
| 1.1.0 | May 31, 2024 |
| 1.0.1 | May 30, 2024 |
#28 in #transmute
386 downloads per month
25KB
434 lines
A proc-macro for generating a struct which can be overlaid. See the documentation for usage and examples.
Usage
#[overlay]
#[derive(Clone, Debug)]
pub struct InquiryCommand {
#[overlay(byte=0, bits=0..8)]
pub op_code: u8,
#[overlay(byte=1)]
pub enable_vital_product_data: bool,
#[overlay(byte=2, bits=0..=7)]
pub page_code: u8,
#[overlay(bytes=3..=4, bits=0..=7)]
pub allocation_length: u16,
...
}
This will create a wrapper struct around an array of bytes, with generated getters and setters for each "field", accessing the bytes/bits at the given offsets.
Todo
- Support for nested structs
- Support for individual fields larger than
u32? compile_error!()/ removeunwrap/expect- And use trybuild
- Emit a fake struct to avoid further errors about it
- Permit missing start/end in byte/bit ranges
- Upgrade to
syn2.0 - Don't drop all other attrs on enum members
- Turn off all syn (crate dep) features (except necessary)
Dependencies
~1.5MB
~39K SLoC