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

Statically assert that a given value is a specific variant of an enum #47

Open
jkshtj opened this issue Apr 11, 2022 · 2 comments
Open

Comments

@jkshtj
Copy link

jkshtj commented Apr 11, 2022

I recently ran into a use case where I was passing down an enum type to a function and I needed that value to be a specific variant of the enum type. First, is it an anti-pattern? Second, if not, Is that something that we'd want to add to this crate?

@konsumlamm
Copy link

konsumlamm commented Apr 11, 2022

Your proposed implementation doesn't assert anything statically, it all happens at runtime (unless you run it in a const context, but the example doesn't do that). To clarify, statically means at compile time.

If you want a function to only take a specific variant, I'd recommend just passing the field(s) of that variant.

@jkshtj
Copy link
Author

jkshtj commented Apr 11, 2022

@konsumlamm, my bad, I'm not sure what I was thinking while drawing up that implementation. I have updated the question to remove the proposed implementation.

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