[][src]Macro const_format::concatcp

macro_rules! concatcp {
    () => { ... };
    ($($arg: expr),* $(,)?) => { ... };
}

Concatenates constants of primitive types into a &'static str.

Each argument is stringified after evaluating it, so concatcp!(1u8 + 3) == "4"

For examples look here

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).

  • 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."#);