Macros for concatenating and formatting constants into &'static str
constants.
Examples
Concatenation
use concatcp;
const NAME: &str = "Bob";
const FOO: &str = concatcp!;
assert_eq!;
Formatting
use formatcp;
const NAME: &str = "John";
const FOO: &str = formatcp!;
assert_eq!;
# const
Limitations
All of the macros from const_format
have these limitations:
-
They cannot take constants that use generic parameters, so while
Type::<u8>::FOO
is fineType::<T>::FOO
is not (T
being a type parameter). -
Integer arguments must have a type inferrable from context, more details in the Integer arguments section.
-
They cannot be used places that take string literals. So
#[doc = "foobar"]
cannot be replaced with#[doc = concatcp!("foo", "bar") ]
.
Integer arguments
Integer arguments must have a type inferrable from context. so if you only pass an integer literal it must have a suffix.
Example of what does compile:
const N: u32 = 1;
assert_eq!;
assert_eq!;
Example of what does not compile:
assert_eq!(const_format::concatcp!(1 + 1, 2 + 1), "23");
Cargo features
None yet.
No-std support
const_format
is unconditionally #![no_std]
, so it can be used anywhere Rust can be used.
Minimum Supported Rust Version
const_format
requires Rust 1.46.0, because it uses looping an branching in const contexts.
Features that require versions of Rust, or the nightly compiler, need to be explicitly enabled with cargo features.