Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Ability to constrain a UUID to a specific version #2579

Closed
jesselang opened this issue Sep 5, 2023 · 2 comments
Closed

Ability to constrain a UUID to a specific version #2579

jesselang opened this issue Sep 5, 2023 · 2 comments

Comments

@jesselang
Copy link

While there is a constraint for a valid UUID, there isn't a constraint for a particular version.

import (
"uuid"
)

id: uuid.Valid
id: "1c7b233b-4806-41a7-bff2-8feebef4870f"

Describe the solution you'd like
A clear and concise description of what you want to happen.

Something like:

import (
"uuid"
)

id: uuid.Valid & uuid.Version(4)
id: "1c7b233b-4806-41a7-bff2-8feebef4870f"

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

There is an operation in the uuid package that returns the version, but I couldn't find a good way to use this as a constraint.

Additional context
Add any other context or screenshots about the feature request here.

@jesselang jesselang added FeatureRequest New feature or request Triage Requires triage/attention labels Sep 5, 2023
@mvdan
Copy link
Member

mvdan commented Sep 6, 2023

How about: https://tip.cuelang.org/play/?id=0Yg5UD02ouh#cue@export@cue

Replace the == 4 with == 3 for example, and you'll see the failure.

With the must builtin per #575, you could rewrite _isV4: true & uuid.Version(id) == 4 into _isV4: must(uuid.Version(id) == 4, "id must be an UUID v4"), for example. A bit nicer for sure, although what you can do today still gets the job done.

@mvdan mvdan removed FeatureRequest New feature or request Triage Requires triage/attention labels Sep 6, 2023
@mvdan
Copy link
Member

mvdan commented Sep 6, 2023

I'm going to convert this into a discussion, because I feel like it's a valid question that others might find useful in the future, and I don't want to close it as a duplicate issue of the must built-in :)

@cue-lang cue-lang locked and limited conversation to collaborators Sep 6, 2023
@mvdan mvdan converted this issue into discussion #2580 Sep 6, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants