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 · May be fixed by #1405
Open

Inline size assertion annotations #1329

jswrenn opened this issue May 20, 2024 · 0 comments · May be fixed by #1405
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, 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],
}
@jswrenn jswrenn added the customer-request Documents customer requests. label May 20, 2024
zoo868e added a commit to zoo868e/zerocopy that referenced this issue Jun 9, 2024
Implem the procedural macro `inline_assert_size_eq` to check the size of
a type at compile time. Additionally, add the test file
`inline_assert_size_eq_failed.rs` to ensure that the macro tirggers a
compile-time error when the size is not as expected
Fixes google#1329
zoo868e added a commit to zoo868e/zerocopy that referenced this issue Jun 9, 2024
Implem the procedural macro `inline_assert_size_eq` to check the size of
a type at compile time. Additionally, add the test file
`inline_assert_size_eq_failed.rs` to ensure that the macro tirggers a
compile-time error when the size is not as expected
Fixes google#1329
@zoo868e zoo868e linked a pull request Jun 9, 2024 that will close this issue
zoo868e added a commit to zoo868e/zerocopy that referenced this issue Jun 9, 2024
Implem the procedural macro `inline_assert_size_eq` to check the size of
a type at compile time. Additionally, add the test file
`inline_assert_size_eq_failed.rs` to ensure that the macro tirggers a
compile-time error when the size is not as expected
Fixes google#1329
zoo868e added a commit to zoo868e/zerocopy that referenced this issue Jun 9, 2024
Implem the procedural macro `inline_assert_size_eq` to check the size of
a type at compile time. Additionally, add the test file
`inline_assert_size_eq_failed.rs` to ensure that the macro tirggers a
compile-time error when the size is not as expected
Fixes google#1329
zoo868e added a commit to zoo868e/zerocopy that referenced this issue Jun 9, 2024
Implem the procedural macro `inline_assert_size_eq` to check the size of
a type at compile time. Additionally, add the test file
`inline_assert_size_eq_failed.rs` to ensure that the macro tirggers a
compile-time error when the size is not as expected
Fixes google#1329
zoo868e added a commit to zoo868e/zerocopy that referenced this issue Jun 9, 2024
Implem the procedural macro `inline_assert_size_eq` to check the size of
a type at compile time. Additionally, add the test file
`inline_assert_size_eq_failed.rs` to ensure that the macro tirggers a
compile-time error when the size is not as expected
Fixes google#1329
zoo868e added a commit to zoo868e/zerocopy that referenced this issue Jun 9, 2024
Implem the procedural macro `inline_assert_size_eq` to check the size of
a type at compile time. Additionally, add the test file
`inline_assert_size_eq_failed.rs` to ensure that the macro tirggers a
compile-time error when the size is not as expected
Fixes google#1329
zoo868e added a commit to zoo868e/zerocopy that referenced this issue Jun 9, 2024
Implem the procedural macro `inline_assert_size_eq` to check the size of
a type at compile time. Additionally, add the test file
`inline_assert_size_eq_failed.rs` to ensure that the macro tirggers a
compile-time error when the size is not as expected
Fixes google#1329
zoo868e added a commit to zoo868e/zerocopy that referenced this issue Jun 9, 2024
Implem the procedural macro `inline_assert_size_eq` to check the size of
a type at compile time. Additionally, add the test file
`inline_assert_size_eq_failed.rs` to ensure that the macro tirggers a
compile-time error when the size is not as expected
Fixes google#1329
zoo868e added a commit to zoo868e/zerocopy that referenced this issue Jun 9, 2024
Implem the procedural macro `inline_assert_size_eq` to check the size of
a type at compile time. Additionally, add the test file
`inline_assert_size_eq_failed.rs` to ensure that the macro tirggers a
compile-time error when the size is not as expected
Fixes google#1329
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
1 participant