Macro build_assert::build_assert
source · macro_rules! build_assert { ($cond:expr $(,)?) => { ... }; ($cond:expr, $($arg:tt)+) => { ... }; }
Expand description
Asserts that a boolean expression is true
at build-time.
In release mode, if the expression is evaluated to false
, or the compiler
or optimizer cannot ensure that the expression is evaluated to true
, this
macro will stop the compilation process.
In debug mode, if the expression is evaluated to false
, this macro will
panic.
Examples
fn foo<const N: usize>() {
build_assert!(N.is_power_of_two(), "N is not a power of two");
}
foo::<16>(); // Fine.
ⓘ
foo::<15>(); // Fails to compile in release mode, panics in debug mode.