Skip to content

Inline layout assertion annotations #1329

Open
@jswrenn

Description

@jswrenn

In some use-cases, it's valuable to define a format that allows for future expansion; e.g., reserves some number of bytes as "padding", that may then be used by later additions to the format so long as the total size of the record does not change; e.g.:

#[repr(C)]
#[derive(IntoBytes, FromBytes, KnownLayout)]
struct Abc {
    field_a: usize,
    field_b: usize,
    padding: [u8; 240],
}

Right now, customers may use static_assertions::assert_eq_size to defend against accidental size changes. In the interest of sparing users from pulling in another dependency, and in the interest of making a best-practice readily available, we might want to consider supporting inline size assertions on non-generic types; e.g.:

#[repr(C)]
#[derive(IntoBytes, FromBytes, KnownLayout)]
#[zerocopy::hint(
    align: core::mem::align_of::<usize>(),
    size: 256,
)]
struct Abc {
    field_a: usize,
    field_b: usize,
    padding: [u8; 240],
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions