google / google/zerocopy

Inline layout assertion annotations

Open
#1,329 0 comments 1 reaction 0 assignees View on GitHub
customer-request
Dominant language
Rust
Stars
2.6k
Forks
179
Avg merge
1d 19h
Merged PRs (30d)
29

Description

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.:
```rust
#[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.:

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.