Rust derive-macro that simplifies integral enum creation
```rust use integral_enum::IntegralEnum;
/// Simple meaningful enum /// (!) repr attribute defaults to u8, to specify custom repr /// use built-in attribute #[repr(integral_value)] it /// can contain only integral values /// like u8, u16, u32, u64, u128 and its signed equivalents. /// /// WARNING: if no explicit #[repr(...)] specified u8 will be used /// as the underlying integral type, actual enum still can have u16 representation, /// for example. For most cases this is enough, but if your enum is large /// enough - specify explicit representation. /// FIXME: Add automatic representation determining
pub enum Emotion { Pain, Hatred, }
// Test it asserteq!(Emotion::tryfrom(0), Ok(Emotion::Pain)); asserteq!(Emotion::tryfrom(1), Ok(Emotion::Hatred)); asserteq!(Emotion::tryfrom(123), Err(())); ```
Macro will automatically generate the following trait implementations: TryFrom, Clone, Copy, PartialEq, Eq, Display, Debug
if you want to disable certain implementation, consider the #[enum_disable(...)]
attribute,
items can be: clone
, copy
, display
, debug
, total_eq
, partial_eq
, try_from
Copy
depends on Clone
, so if you disable
Clone
generation, Copy
generation will be disabled also.total_eq
disables Eq
trait implementationExample:
```rust use integral_enum::IntegralEnum;
pub enum Emotion { Pain, Hatred, }
println!("{}", Emotion::Pain); // Compile error ```
PartialOrd + Ord
also?