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

Closed
opened 2024-05-19 18:29:45 -05:00 by alexipeck · 2 comments
alexipeck commented 2024-05-19 18:29:45 -05:00 (Migrated from github.com)
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

```rust 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 commented 2024-05-20 20:07:11 -05:00 (Migrated from github.com)

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);
| ^^^^^^^^

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 commented 2024-05-22 03:10:01 -05:00 (Migrated from github.com)

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.

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 in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-uuid-rs/uuid#756
No description provided.