Macro qed::const_assert

source ·
macro_rules! const_assert {
    ($x:expr $(,)?) => { ... };
}
Expand description

Asserts that a boolean expression is true at compile time.

This will result in a compile time type error if the boolean expression does not evaluate to true.

§Uses

Assertions are always checked in both debug and release builds and cannot be disabled.

Unsafe code and as casts may rely on const_assert! to enforce runtime invariants that, if violated, could lead to unsafety.

Other use-cases of const_assert! include limiting supported platforms and architectures.

§Examples

// Assert at compile time that the target platform has at least 32-bit
// `usize`.
qed::const_assert!(usize::BITS >= u32::BITS);

Assertion failures will result in a compile error:

qed::const_assert!("non-empty string".is_empty());