Macro static_assertions::const_assert
[−]
[src]
macro_rules! const_assert { ($($xs:expr),+ $(,)*) => { ... }; ($label:ident; $($xs:tt)+) => { ... }; }
Asserts at compile-time that the constant expression evaluates to true.
There also exists const_assert_eq for
validating whether a sequence of expressions are equal to one another.
Example
Constant expressions can be ensured to have certain properties via this
macro If the expression evaluates to false, the file will fail to compile.
This is synonymous to static_assert in C++.
As a limitation, a unique label is required if the macro is used outside of a function.
const FIVE: usize = 5; const_assert!(twenty_five; FIVE * FIVE == 25); fn main() { const_assert!(2 + 2 == 4); const_assert!(FIVE - FIVE == 0); // Produces a compilation failure: // const_assert!(1 >= 2); }