Peternator7 / strum

A small rust library for adding custom derives to enums
https://crates.io/crates/strum
MIT License
1.78k stars 150 forks source link

is_* methods #252

Closed MendyBerger closed 1 year ago

MendyBerger commented 1 year ago

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 commented 1 year ago

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