Macro build_assert::build_assert_eq
source · macro_rules! build_assert_eq { ($left:expr, $right:expr $(,)?) => { ... }; ($left:expr, $right:expr, $($arg:tt)+) => { ... }; }
Expand description
Asserts that two expressions are equal to each other at build-time (using PartialEq).
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 A: usize, const B: usize>() {
build_assert_eq!(A, B, "A and B are not equal");
}
foo::<1, 1>(); // Fine.
ⓘ
foo::<1, 2>(); // Fails to compile in release mode, panics in debug mode.