[][src]Macro const_format::concatc

macro_rules! concatc {
    () => { ... };
    ($($anything:tt)*) => { ... };
}
This is supported on crate feature fmt only.

Concatenates constants of standard library and/or user-defined types into a &'static str.

User defined types must implement the FormatMarker trait and and have a const_display_fmt method (as described in the trait) to be concatenated.

Stable equivalent

For an equivalent macro which can be used in stable Rust (1.46.0 onwards), but can only concatenate primitive types, you can use the concatcp macro.

Limitations

This macro has the limitations described in here.

Examples

With standard library types

#![feature(const_mut_refs)]

use const_format::concatc;

assert_eq!(concatc!("There is ", 99u8, " monkeys!"), "There is 99 monkeys!");

With user-defined types

#![feature(const_mut_refs)]

use const_format::{Formatter, Sliced, concatc, impl_fmt};

const STRING: &str = "foo bar baz";

assert_eq!(concatc!(Sliced(STRING, 4..8), Foo), "bar table");

struct Foo;

impl_fmt!{
    impl Foo;
    const fn const_display_fmt(&self, fmt: &mut Formatter<'_>) -> const_format::Result {
        fmt.write_str("table")
    }
}