Expand description
Compile time assertions.
This crate contains compile time assertion macros used for maintaining safety invariants or limiting platform support. If the assertion is false, a compiler error is emitted.
Examples
qed::const_assert!(usize::BITS >= u32::BITS);
qed::const_assert_eq!("Veni, vidi, vici".len(), 16);
qed::const_assert_ne!('∎'.len_utf8(), 1);
qed::const_assert_matches!(NonZeroU8::new(42), Some(nz) if nz.get() == 42);
Assertion failures will result in a compile error:
ⓘ
qed::const_assert!("non-empty string".is_empty());
Macros
- Asserts that a boolean expression is true at compile time.
- Asserts that a byte slice does not contain any NUL (
\0
) bytes. - Asserts that two expressions are equal to each other (using
PartialEq
) at compile time. - Asserts that an expression matches any of the given patterns at compile time.
- Asserts that two expressions are not equal to each other (using
PartialEq
) at compile time. - Asserts that two types have the same size at compile time.
- Construct a const
CStr
from the given bytes at compile time and assert that the given bytes are a validCStr
(NUL terminated with no interior NUL bytes). - Construct a const
CStr
from the givenstr
at compile time and assert that the givenstr
bytes are a validCStr
(NUL terminated with no interior NUL bytes).