overlay_macro

Crates.iooverlay_macro
lib.rsoverlay_macro
version2.0.0
sourcesrc
created_at2024-05-30 17:16:41.451808
updated_at2024-07-03 17:40:08.282696
descriptionA proc-macro for implementing Overlay, to reinterpret a slice of bytes as a bit/byte packed struct
homepagehttps://github.com/bobrippling/overlay-rs
repositoryhttps://github.com/bobrippling/overlay-rs
max_upload_size
id1257086
size32,640
Rob Pilling (bobrippling)

documentation

README

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!() / remove unwrap / expect
    • And use trybuild
    • Emit a fake struct to avoid further errors about it
  • Permit missing start/end in byte/bit ranges
  • Upgrade to syn 2.0
  • Don't drop all other attrs on enum members
  • Turn off all syn (crate dep) features (except necessary)
Commit count: 63

cargo fmt