derive_is_enum_variant
Stop writing pub is_whatever(&self) -> bool
for your enum
s by hand -- it's a
pain! Just #[derive(is_enum_variant)]
instead!
Add derive_is_enum_variant
to your crate's Cargo.toml
:
toml
[dependencies]
derive_is_enum_variant = "<insert-latest-version-here>"
And then add #[derive(is_enum_variant)]
to your enum
definitions:
```rust
extern crate deriveisenum_variant;
pub enum Pet { Doggo, Kitteh, }
fn main() { let pet = Pet::Doggo;
assert!(pet.is_doggo());
assert!(!pet.is_kitteh());
} ```
By default, the predicates are named is_snake_case_of_variant_name
. You can
use any name you want instead with #[is_enum_variant(name = "..")]
:
```rust
pub enum Pet { #[isenumvariant(name = "isrealgood_boy")] Doggo, Kitteh, }
let pet = Pet::Doggo; assert!(pet.isrealgood_boy()); ```
If you don't want to generate a predicate for a certain variant, you can use
#[is_enum_variant(skip)]
:
```rust
pub enum Errors { Io(::std::io::Error),
#[doc(hidden)]
#[is_enum_variant(skip)]
__NonExhaustive,
}
```
Licensed under either of
LICENSE-APACHE
or http://www.apache.org/licenses/LICENSE-2.0)LICENSE-MIT
or http://opensource.org/licenses/MIT)at your option.
See CONTRIBUTING.md for hacking!
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
License: Apache-2.0/MIT