Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline size assertion annotations #1329

Open
jswrenn opened this issue May 20, 2024 · 0 comments
Open

Inline size assertion annotations #1329

jswrenn opened this issue May 20, 2024 · 0 comments
Labels
customer-request Documents customer requests.

Comments

@jswrenn
Copy link
Collaborator

jswrenn commented May 20, 2024

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)]
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)]
#[zerocopy::assert_size(256)]
struct Abc {
    field_a: usize,
    field_b: usize,
    padding: [u8; 240],
}
@jswrenn jswrenn added the customer-request Documents customer requests. label May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-request Documents customer requests.
Projects
None yet
Development

No branches or pull requests

1 participant