#structural #assertions #struct #layout #testing #assert #field

macro structural-assert

Proc macro to generate tests which make assertions about a struct's layout

1 unstable release

0.1.0 Apr 21, 2021

#19 in #structural

MIT license

8KB
128 lines

structural-assert

Inline assertions of the structural layout of a struct. This was implemented exclusively to make it easier to implement structs which conform to a specification which defines the start and end of a field. The specific use case was initially to help faithfully reproduce structures from the NVMe spec.

Usage

ust structural_assert::test_structure;

#[test_structure(size = 20)]
#[repr(C, packed)]
pub struct Foo {
    #[loc(0:0)]
    pub a: u8,
    #[loc(1:1)]
    pub b: u8,
    #[loc(2:3)]
    pub c: u16,
    #[loc(4:19)]
    pub d: u128,
}

Dependencies

~1.5MB
~34K SLoC