macro_rules! str_join {
($sep:expr, $(&)? []) => { ... };
($sep:expr, $slice:expr $(,)*) => { ... };
}
Expand description
Macro equivalent of <[&str]>::join
, which takes constants as arguments.
This acts like a compile-time-evaluated version of this function:
pub const fn str_join(
delimiter: impl StrOrChar,
strings: &'static [&'static str],
) -> &'static str
Where impl StrOrChar
is either a &'static str
or char
ยงExample
use konst::string::str_join;
{
const COMMA: &str = ",";
const S: &[&str] = &["these", "are", "words"];
assert_eq!(str_join!(COMMA, S), "these,are,words");
}
assert_eq!(str_join!(",", &[]), "");
assert_eq!(str_join!(" ", &["foo", "bar", "baz"]), "foo bar baz");
// char separator
assert_eq!(str_join!(' ', &["foo", "bar", "baz"]), "foo bar baz");