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

Use const identifier in uuid macro #764

Merged
merged 3 commits into from
Jul 8, 2024
Merged

Use const identifier in uuid macro #764

merged 3 commits into from
Jul 8, 2024

Conversation

Vrajs16
Copy link
Contributor

@Vrajs16 Vrajs16 commented Jun 29, 2024

The code below works when the user doesn't enable macro-diagnostics feature.

It's not possible to convert the value of identifier into a string literal at compile time, but is there another way we can go about this so we can give more details when this feature is enabled.

If not, we can just paste the same code inside the macro where macro-diagnostics is enabled so that at least there wouldn't be a compile time error.

($uuid:ident) => {{
    const OUTPUT: $crate::Uuid = match $crate::Uuid::try_parse($uuid) {
        $crate::__macro_support::Ok(u) => u,
        $crate::__macro_support::Err(_) => panic!("invalid UUID"),
    };
    OUTPUT
}};

Closes #756

@Vrajs16 Vrajs16 marked this pull request as ready for review June 29, 2024 12:13
@KodrAus
Copy link
Member

KodrAus commented Jun 29, 2024

Thanks @Vrajs16! We should be able to support this in the procedural macro too by modifying this block here: https://github.com/uuid-rs/uuid/blob/main/macros/src/lib.rs#L70-L83.

We'd change it to parse a syn::Expr instead of a syn::Lit. If we match a syn::ExprLit { lit: syn::Lit::Str(str) } from that expression then we'd follow the old path that parses the string, otherwise we generate the same code as what you're doing in the macro_rules macro.

Is this something you'd like to take a shot at implementing? If not, I'll be happy to merge this change once it passes CI and update the macros myself.

@Vrajs16
Copy link
Contributor Author

Vrajs16 commented Jun 30, 2024

Hi @KodrAus, not sure how I would generate the same the code in build_uuid function.
I was thinking, when a user puts a variable inside the uuid! macro, macro rules will match ($uuid:ident) => ... and then we just use the same code as the below:

const OUTPUT: $crate::Uuid = match $crate::Uuid::try_parse($uuid) { 
    $crate::__macro_support::Ok(u) => u,
    $crate::__macro_support::Err(_) => panic!("invalid UUID"),
};
OUTPUT

@KodrAus
Copy link
Member

KodrAus commented Jun 30, 2024

Ah, sorry I'd forgotten we still wrap the procedural macro in a regular macro-rules one. Duplicating the match arm in the case where macro-diagnostics is enabled should be all we need.

src/macros.rs Outdated Show resolved Hide resolved
src/macros.rs Outdated Show resolved Hide resolved
Copy link
Member

@KodrAus KodrAus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Vrajs16! This looks good to me.

@KodrAus KodrAus merged commit 66b4fce into uuid-rs:main Jul 8, 2024
21 checks passed
mergify bot pushed a commit to andrzejressel/pulumi-wasm that referenced this pull request Jul 9, 2024
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [uuid](https://togithub.com/uuid-rs/uuid) | workspace.dependencies | minor | `1.9.1` -> `1.10.0` |

---

### Release Notes

<details>
<summary>uuid-rs/uuid (uuid)</summary>

### [`v1.10.0`](https://togithub.com/uuid-rs/uuid/releases/tag/1.10.0)

[Compare Source](https://togithub.com/uuid-rs/uuid/compare/1.9.1...1.10.0)

#### Deprecations

This release deprecates and renames the following functions:

-   `Builder::from_rfc4122_timestamp` -> `Builder::from_gregorian_timestamp`
-   `Builder::from_sorted_rfc4122_timestamp` -> `Builder::from_sorted_gregorian_timestamp`
-   `Timestamp::from_rfc4122` -> `Timestamp::from_gregorian`
-   `Timestamp::to_rfc4122` -> `Timestamp::to_gregorian`

#### What's Changed

-   Use const identifier in uuid macro by [@&#8203;Vrajs16](https://togithub.com/Vrajs16) in [uuid-rs/uuid#764
-   Rename most methods referring to RFC4122 by [@&#8203;Mikopet](https://togithub.com/Mikopet) / [@&#8203;KodrAus](https://togithub.com/KodrAus) in [uuid-rs/uuid#765
-   prepare for 1.10.0 release by [@&#8203;KodrAus](https://togithub.com/KodrAus) in [uuid-rs/uuid#766

#### New Contributors

-   [@&#8203;Vrajs16](https://togithub.com/Vrajs16) made their first contribution in [uuid-rs/uuid#764

**Full Changelog**: uuid-rs/uuid@1.9.1...1.10.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/andrzejressel/pulumi-wasm).
renovate bot added a commit to spiraldb/vortex that referenced this pull request Jul 9, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [uuid](https://togithub.com/uuid-rs/uuid) | workspace.dependencies |
minor | `1.9.1` -> `1.10.0` |

---

### Release Notes

<details>
<summary>uuid-rs/uuid (uuid)</summary>

### [`v1.10.0`](https://togithub.com/uuid-rs/uuid/releases/tag/1.10.0)

[Compare
Source](https://togithub.com/uuid-rs/uuid/compare/1.9.1...1.10.0)

#### Deprecations

This release deprecates and renames the following functions:

- `Builder::from_rfc4122_timestamp` ->
`Builder::from_gregorian_timestamp`
- `Builder::from_sorted_rfc4122_timestamp` ->
`Builder::from_sorted_gregorian_timestamp`
-   `Timestamp::from_rfc4122` -> `Timestamp::from_gregorian`
-   `Timestamp::to_rfc4122` -> `Timestamp::to_gregorian`

#### What's Changed

- Use const identifier in uuid macro by
[@&#8203;Vrajs16](https://togithub.com/Vrajs16) in
[uuid-rs/uuid#764
- Rename most methods referring to RFC4122 by
[@&#8203;Mikopet](https://togithub.com/Mikopet) /
[@&#8203;KodrAus](https://togithub.com/KodrAus) in
[uuid-rs/uuid#765
- prepare for 1.10.0 release by
[@&#8203;KodrAus](https://togithub.com/KodrAus) in
[uuid-rs/uuid#766

#### New Contributors

- [@&#8203;Vrajs16](https://togithub.com/Vrajs16) made their first
contribution in
[uuid-rs/uuid#764

**Full Changelog**:
uuid-rs/uuid@1.9.1...1.10.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/spiraldb/vortex).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MjUuMSIsInVwZGF0ZWRJblZlciI6IjM3LjQyNS4xIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6W119-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
kodiakhq bot pushed a commit to pdylanross/fatigue that referenced this pull request Jul 9, 2024
Bumps uuid from 1.9.1 to 1.10.0.

Release notes
Sourced from uuid's releases.

1.10.0
Deprecations
This release deprecates and renames the following functions:

Builder::from_rfc4122_timestamp -> Builder::from_gregorian_timestamp
Builder::from_sorted_rfc4122_timestamp -> Builder::from_sorted_gregorian_timestamp
Timestamp::from_rfc4122 -> Timestamp::from_gregorian
Timestamp::to_rfc4122 -> Timestamp::to_gregorian

What's Changed

Use const identifier in uuid macro by @​Vrajs16 in uuid-rs/uuid#764
Rename most methods referring to RFC4122 by @​Mikopet / @​KodrAus in uuid-rs/uuid#765
prepare for 1.10.0 release by @​KodrAus in uuid-rs/uuid#766

New Contributors

@​Vrajs16 made their first contribution in uuid-rs/uuid#764

Full Changelog: uuid-rs/uuid@1.9.1...1.10.0



Commits

4b4c590 Merge pull request #766 from uuid-rs/cargo/1.10.0
68eff32 Merge pull request #765 from uuid-rs/chore/time-fn-deprecations
3d5384d update docs and deprecation messages for timestamp fns
de50f20 renaming rfc4122 functions
4a88417 prepare for 1.10.0 release
66b4fce Merge pull request #764 from Vrajs16/main
8896e26 Use expr instead of ident
09973d6 Added changes
6edf3e8 Use const identifer in uuid macro
See full diff in compare view




Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options

You can trigger Dependabot actions by commenting on this PR:

@dependabot rebase will rebase this PR
@dependabot recreate will recreate this PR, overwriting any edits that have been made to it
@dependabot merge will merge this PR after your CI passes on it
@dependabot squash and merge will squash and merge this PR after your CI passes on it
@dependabot cancel merge will cancel a previously requested merge and block automerging
@dependabot reopen will reopen this PR if it is closed
@dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
@dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
@dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
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

Successfully merging this pull request may close these issues.

uuid!() macro can't handle a constant &str passed in
2 participants