Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use concatcp to match str #17

Open
Armiixteryx opened this issue Mar 28, 2021 · 2 comments
Open

Cannot use concatcp to match str #17

Armiixteryx opened this issue Mar 28, 2021 · 2 comments

Comments

@Armiixteryx
Copy link

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!

@rodrimati1992
Copy link
Owner

rodrimati1992 commented Mar 28, 2021

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
Copy link
Owner

rodrimati1992 commented Dec 6, 2024

Update: the latest release (0.2.34) makes the macros usable in patterns when the "rust_1_83" crate feature is enabled, and you enable the inline_const_pat unstable language feature in your crate.

I'll close this issue once the language feature is usable on stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants