Macro konst::string::str_concat

source ·
macro_rules! str_concat {
    ($(&)? []) => { ... };
    ($slice:expr $(,)*) => { ... };
}
Expand description

Macro equivalent of <[&str]>::concat, which takes a constant as an argument.

This acts like a compile-time-evaluated version of this function:

pub const fn str_concat(strings: &'static [impl StrOrChar]) -> &'static str

Where impl StrOrChar is either a &'static str or char

§Example

use konst::string::str_concat;

{
    const S: &[&str] = &["these ", "are ", "words"];
    assert_eq!(str_concat!(S), "these are words");
    
    assert_eq!(str_concat!(&[]), "");
    
    assert_eq!(str_concat!(&["foo", "bar", "baz"]), "foobarbaz");
}

{
    const C: &[char] = &['c', 'h', 'a', 'r', 's'];
    assert_eq!(str_concat!(C), "chars");
    
    assert_eq!(str_concat!(&['q'; 10]), "qqqqqqqqqq");
}