Attribute Macro open_enum

Source
#[open_enum]
Expand description

Constructs an open enum from a Rust enum definition, allowing it to represent more than just its listed variants.

See the crate documentation for more details.

§Example

#[open_enum]
#[derive(Debug)]
enum Color {
    Red,
    Green,
    Blue,
    Orange,
    Black,
}

assert_eq!(Color::Red, Color(0));
assert_eq!(Color(10).0, 10);

§Options

  • allow_alias[ = $bool]: default false. Allows duplicate discriminant values for variants.
  • inner_vis = $vis: default pub. Specifies the visibility of the inner integer.

§Integer type

open_enum configures the discriminant type by intercepting a repr attribute on the enum. If done, the open enum is #[repr(transparent)] over the provided integer type. Otherwise, variant discriminants are interpreted as isize and an automatic integer type chosen.

§PartialEq/Eq

Open enums implement PartialEq and Eq in order to work in a match statement.