enum_fun/
lib.rs

1#![warn(missing_docs)]
2
3//! Silly enum helpers.
4
5pub use enum_fun_macros::Name;
6
7/// Generates `is_*` predicate methods for each enum variant.
8///
9/// The name of a predicate method is `is_` followed by the variant's
10/// identifier in snake_case. `Foo` becomes `is_foo` and `HelloWorld`
11/// becomes `is_hello_world`.
12///
13/// ```rust
14/// use enum_fun::Predicates;
15///
16/// #[derive(Predicates)]
17/// enum Words {
18///     Foo,
19///     Bar,
20/// #   SnakeCaseTest,
21/// }
22///
23/// use Words::*;
24///
25/// assert!(Foo.is_foo());
26/// assert!(!Foo.is_bar());
27///
28/// assert!(Bar.is_bar());
29/// assert!(!Bar.is_foo());
30/// #
31/// # assert!(SnakeCaseTest.is_snake_case_test());
32/// ```
33pub use enum_fun_macros::Predicates;
34
35/// Generates inherent constants and an iterator method
36/// to enable iterating and indexing the enum variants.
37///
38/// ```rust
39/// use enum_fun::Variants;
40///
41/// #[derive(Debug, PartialEq, Variants)]
42/// enum Words {
43///     Foo,
44///     Bar,
45///     Baz,
46/// }
47///
48/// use Words::*;
49///
50/// assert_eq!(Words::VARIANT_COUNT, 3);
51/// assert_eq!(Words::VARIANTS, [Foo, Bar, Baz]);
52/// assert_eq!(Words::variants().collect::<Vec<_>>(), vec![Foo, Bar, Baz]);
53/// ```
54///
55/// The return type of the `variants()` method is an `impl ExactSizeIterator<Item = Self>`.
56///
57/// Only enums without fields are supported.
58pub use enum_fun_macros::Variants;