Rust compile-time assertions.
Use assert_eq_size!
to ensure two types are the same size:
```rust asserteqsize!([u8; 4], u32); asserteqsize!([u8; 8], u64, (u32, u32), (u32, u16, u16), ...);
// Fails to compile asserteqsize!(u16, u64); ```
Use assert_eq_size_val!
to ensure two values are the same size:
```rust let x: u32 = 42; let y: u32 = 10; asserteqsize_val!(x, y, [0u8; 4]);
// Fails to compile asserteqsize_val!(x, 0u8); ```
Note: Both macros support multiple arguments and are not restricted by the recursion limit.
Limitation: Due to implementation details, these macros can only be called
from within the context of a function. This may change when mem::size_of
becomes a const fn
.
A constant expression can be ensured to evaluate to true
at compile-time.
```rust const_assert!(1 + 1 == 2);
// Supports constants const FIVE: usize = 5;
// Supports comma and semicolon-separated conditions constassert!(4 > 3, 3 + 2 == FIVE); constassert! { FIVE + FIVE == 10; FIVE / FIVE == 1; }
// Fails to compile const_assert!(2 != 2); ```
Limitation: Due to implementation details, const_assert!
can only be
called from within the context of a function.
This project is released under either:
at your choosing.