const_format_crates icon indicating copy to clipboard operation
const_format_crates copied to clipboard

Cannot use concatcp to match str

Open Armiixteryx opened this issue 3 years ago • 1 comments

Hello, currently I am having an issue when trying to match strings using concatcp:

Let suppose we have following code:

use const_format::concatcp;
fn main() {
    const ABC: &str = "abc/";
    let s = "abc/xyz";
    match s {
        concatcp!(ABC, "xyz") => todo!(),
        _ => todo!()
    }
}

In compilation, I get following error:

image

Using std's concat macro works, but with concatcp I can use a constant to avoid repetitions, in this case, of abc/.

Thank you for this crate!

Armiixteryx avatar Mar 28 '21 18:03 Armiixteryx

There's no way on stable to make that work yet, so you'll have to do this for now:

use const_format::concatcp;
fn main() {
    const ABC: &str = "abc/";
    let s = "abc/xyz";
    const C: &str = concatcp!(ABC, "xyz");
    match s {
        C => todo!(),
        _ => todo!()
    }
}

when inline const is stabilized, then I'll update this crate to use it and make your code work.

I'll leave this issue open until that happens.

rodrimati1992 avatar Mar 28 '21 18:03 rodrimati1992