Macro compile_fmt::compile_assert
source · macro_rules! compile_assert { ($check:expr, $($arg:tt)+) => { ... }; }
Expand description
Version of the assert!
macro with the ability to format args in compile time.
The first argument of the macro must be a boolean value. The remaining arguments have the same syntax
as in the compile_args!
macro.
Examples
use compile_fmt::{compile_assert, fmt};
const fn check_args(x: usize, s: &str) {
const MAX_STR_LEN: usize = 10;
compile_assert!(
x < 1_000,
"`x` should be less than 1000 (got: ",
x => fmt::<usize>(), ")"
);
compile_assert!(
s.len() <= MAX_STR_LEN,
"String is too long (expected at most ", MAX_STR_LEN,
" bytes; got ", s.len() => fmt::<usize>(), " bytes)"
);
// main logic...
}