macro_rules! assertcp_ne {
($($parameters:tt)*) => { ... };
}
Expand description
Compile-time inequality assertion with formatting.
This macro requires the "assertcp"
feature to be exported.
§Syntax
This macro uses the same syntax
for the format string and formatting arguments as the
formatcp
macro.
§Limitations
This macro can only take constants of these types as arguments:
-
&str
-
i*
/u*
(all the primitive integer types). -
char
-
bool
This macro also has these limitations:
-
It can only use constants that involve concrete types, so while a
Type::<u8>::FOO
in an argument would be fine,Type::<T>::FOO
would not be (T
being a type parameter). -
Integer arguments must have a type inferrable from context, as described in the integer arguments section in the root module .
§Examples
§Passing assertion
use const_format::assertcp_ne;
assertcp_ne!(std::mem::size_of::<usize>(), 1usize, "Oh no, usize is tiny!");
const CHAR: char = ';';
assertcp_ne!(CHAR, '.', "CHAR must not be a dot!");
§Failing assertion
This example demonstrates a failing assertion, and how the compiler error looks like as of 2023-10-14.
use const_format::assertcp_ne;
const NAME: &str = "";
assertcp_ne!(NAME, "", "NAME must not be empty!");
This is the compiler output:
error[E0080]: evaluation of constant value failed
--> const_format/src/macros/assertions/assertcp_macros.rs:297:14
|
8 | assertcp_ne!(NAME, "", "NAME must not be empty!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at '
assertion failed: `(left != right)`
left: `""`
right: `""`
NAME must not be empty!
', const_format/src/macros/assertions/assertcp_macros.rs:8:14