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

is_* methods #252

Closed
MendyBerger opened this issue Feb 16, 2023 · 1 comment · Fixed by #257
Closed

is_* methods #252

MendyBerger opened this issue Feb 16, 2023 · 1 comment · Fixed by #257

Comments

@MendyBerger
Copy link
Contributor

I wrote a little derive macro that generates is_* methods for each enum variant, and I wonder if strum would be a good home for it. If so, I'll open a PR.

Example:

#[derive(Is)]
enum Foo {
    Bar {},
    Biz
}

The Is derive will add is_bar() and is_biz() methods, similar to Option::is_some(), Option::is_none(), Result::is_ok(), etc.

I think that:

if foo.is_bar() {
    ....
}

is a lot cleaner then:

if matches!(foo, Foo::Bar { .. }) {
    ....
}

Thoughts?

@Peternator7
Copy link
Owner

Hi @MendyBerger , that seems like a great fit for strum. If you're interested, I'd be happy to accept a PR. Let me know if I can help

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 a pull request may close this issue.

2 participants