How to concatenate static strings in Rust

Since I was essentially trying to emulate C macros, I tried to solve the problem with Rust macros and succeeded:

macro_rules! description {
    () => ( "my program" )
}
macro_rules! version {
    () => ( env!("CARGO_PKG_VERSION") )
}
macro_rules! version_string {
    () => ( concat!(description!(), " v", version!()) )
}

It feels a bit ugly to use macros instead of constants, but it works as expected.

Leave a Comment