Feature request: compile-time layout tests · Issue #2786 · rust-lang/rust-bindgen (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
Bindgen currently emits unit tests to check layout. However, these are quite difficult to run for a cross-compiled target as there may be no way to run code on the target as part of the build process. Targets not supporting std
, i.e. embedded, are harder again to run the tests on.
With the stabilization of core::mem::offset_of
it should now be possible to convert the layout tests into compile-time assertions like below. This would make it much easier for embedded users to run these tests.
const _LAYOUT_TEST_S: () = {
assert!(::core::mem::size_of::() == 4);
assert!(::core::mem::align_of::() == 4);
assert!(::core::mem::offset_of!(S, field1) == 0);
// etc.
};