GitXplorerGitXplorer
f

derive_is_enum_variant

public
23 stars
2 forks
4 issues

Commits

List of commits on branch master.
Unverified
5bbc021b7bf41eecb1a6825cd31af57edbbbeb45

Bump to 0.1.1

ffitzgen committed 7 years ago
Unverified
dfcc92e9e4aa102bf0a096b2722cbfaf373fef57

Mark generated predicates `#[inline]` and allow them to be unused

ffitzgen committed 7 years ago
Unverified
6e965dc1b3c33bf1d1450bf84243a453b6f76826

Ignore the README up-to-date check in CI

ffitzgen committed 7 years ago
Unverified
4adb97f1aafb8d011e9892773f4121665f9ca3c2

Initial commit: it works!

ffitzgen committed 7 years ago

README

The README file for this repository.

derive_is_enum_variant

derive_is_enum_variant

Build Status

Stop writing pub is_whatever(&self) -> bool for your enums by hand -- it's a pain! Just #[derive(is_enum_variant)] instead!

Usage

Add derive_is_enum_variant to your crate's Cargo.toml:

[dependencies]
derive_is_enum_variant = "<insert-latest-version-here>"

And then add #[derive(is_enum_variant)] to your enum definitions:

#[macro_use]
extern crate derive_is_enum_variant;

#[derive(is_enum_variant)]
pub enum Pet {
    Doggo,
    Kitteh,
}

fn main() {
    let pet = Pet::Doggo;

    assert!(pet.is_doggo());
    assert!(!pet.is_kitteh());
}

Customizing Predicate Names

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 = "..")]:

#[derive(is_enum_variant)]
pub enum Pet {
    #[is_enum_variant(name = "is_real_good_boy")]
    Doggo,
    Kitteh,
}

let pet = Pet::Doggo;
assert!(pet.is_real_good_boy());

Skipping Predicates for Certain Variants

If you don't want to generate a predicate for a certain variant, you can use #[is_enum_variant(skip)]:

#[derive(is_enum_variant)]
pub enum Errors {
    Io(::std::io::Error),

    #[doc(hidden)]
    #[is_enum_variant(skip)]
    __NonExhaustive,
}

License

Licensed under either of

at your option.

Contribution

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