static-assertions
static-assertions copied to clipboard
Add assert_sizeof_eq!
to equate size of a type to a literal usize at compile time.
I try to improve the error message with std::concat! but it doesn't help much:
Playground link for this newly added macro: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=3f807d04413a9706b8afc8472895f664
I cannot reproduce locally the error on CI with nightly toolchain:
error[E0019]: constant contains unimplemented expression type
Error: --> tests/eq_size.rs:8:1
|
8 | assert_sizeof_eq!(u32, 4);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
Is there any reason for adding a new macro for this, instead of just using for example
use std::mem::size_of;
const_assert_eq!(size_of::<u32>(), 4);
?