Concat `&'static str` at compile time?

37 points pro_hodler

Hello. I'm trying to concatenate associate static strings coming from a generic tuple via https://lib.rs/const_format. Here's the code:

use const_format::concatcp;
use core::marker::PhantomData;

trait Name {
    const NAME: &'static str;
}

trait Prefix: Name {}

trait Root: Name {}

struct Kilo;

impl Prefix for Kilo {}

struct Meter;

impl Root for Meter {}

impl Name for Kilo {
    const NAME: &'static str = "kilo";
}

impl Name for Meter {
    const NAME: &'static str = "meter";
}

impl<P: Prefix, R: Root> Name for (P, R) {
    const NAME: &'static str = concatcp!(P::NAME, R::NAME);
}

fn main() {}

Unfortunately, it doesn't compile with the following error:

can't use generic parameters from outer function
use of generic parameter from outer function
rustc (E0401)

Can you suggest any workarounds for this specific use case?

UPD: I'll try porting https://lib.rs/const-concat to stable & see if it fits my use case