static_assertions
Rust compile-time assertions.
Usage
Assert Equal Size
Use assert_eq_size!
to ensure two types are the same size:
assert_eq_size!;
assert_eq_size!;
// Fails to compile
assert_eq_size!;
Use assert_eq_size_val!
to ensure two values are the same size:
let x: u32 = 42;
let y: u32 = 10;
assert_eq_size_val!;
// Fails to compile
assert_eq_size_val!;
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
.
Assert Constant Expression
A constant expression can be ensured to evaluate to true
at compile-time.
const_assert!;
// Supports constants
const FIVE: usize = 5;
// Supports comma and semicolon-separated conditions
const_assert!;
const_assert!
// Fails to compile
const_assert!;
Limitation: Due to implementation details, const_assert!
can only be
called from within the context of a function.
License
This project is released under either:
at your choosing.