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

uuid!() macro can't handle a constant &str passed in #756

Open
alexipeck opened this issue May 19, 2024 · 2 comments
Open

uuid!() macro can't handle a constant &str passed in #756

alexipeck opened this issue May 19, 2024 · 2 comments

Comments

@alexipeck
Copy link

alexipeck commented May 19, 2024

const TEST: &str = "00000000-0000-0000-0000-000000000000";
let uid: Uuid = uuid::uuid!(TEST);

no rules expected the token TEST
no rules expected this token in macro call
macros.rs(16, 14): while trying to match meta-variable $uuid:literal

@alexipeck
Copy link
Author

I realise now that this has been documented, is there a reason this marco can't support this use case?

Tokens that aren't string literals are also rejected:
let uuid_str: &str = "550e8400e29b41d4a716446655440000";
let uuid = uuid!(uuid_str);
Provides the following compilation error:

error: expected string literal
|
| let uuid = uuid!(uuid_str);
| ^^^^^^^^

@KodrAus
Copy link
Member

KodrAus commented May 22, 2024

Hi @alexipeck 👋 The problem here is just that we can’t get the actual value of the string at compile time in order to parse it in the macro if it’s not a string literal.

I do think this can still be implemented now though since we have a const parser for UUIDs available to us. It’s just a limitation of the current macro that needs to be lifted.

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