macro_rules! concatcp { () => { ... }; ($($arg: expr),* $(,)?) => { ... }; }
Expand description
Concatenates constants of primitive types into a &'static str
.
Each argument is stringified after evaluating it, so concatcp!(1u8 + 3) == "4"
concatcp
stands for “concatenate constants (of) primitives”
§Limitations
This macro can only take constants of these types as inputs:
-
&str
-
i*
/u*
(all the primitive integer types). -
char
-
bool
This macro also shares the limitations described in here as well.
§Examples
§Literal arguments
use const_format::concatcp;
const MSG: &str = concatcp!(2u8, "+", 2u8, '=', 2u8 + 2);
assert_eq!(MSG, "2+2=4");
§const
arguments
use const_format::concatcp;
const PASSWORD: &str = "password";
const fn times() -> u64 { 10 }
const MSG: &str =
concatcp!("The password is \"", PASSWORD, "\", you can only guess ", times(), " times.");
assert_eq!(MSG, r#"The password is "password", you can only guess 10 times."#);