varflags

Attribute Macro varflags 

Source
#[varflags]
Expand description

Attribute marking an enum declaration as input for Varflags.

This attribute requires a unit-only enum with more than 0 variants and all of the variants’ discriminants should have exactly one bit set. It can’t have more than 128 variants.

It does exactly this list of things:

  • Derives [Clone] for the enum. It is required, so you don’t have to derive or implement it manually.
  • Adds #[repr] attribute for the enum which can be set to either u8, u16, u32, u64 or u128.
    Keep in mind, that #[repr(u128)] is currently unstable.
  • Consumes #[flag] and #[shift] variant attributes and sets their variants’ discriminants accordingly.
  • Calculates and asigns unused discriminants for variants wihout explicit discriminants or attributes.
  • Creates a private module called after enum name converted to snake case with _varflags appended.
  • Generates [From] implementation for representing (unsigned integer) type from the enum.
  • Generates [Not][core::ops::Not], [BitAnd][core::ops::BitAnd], [BitOr][core::ops::BitOr] and [BitXor][core::ops::BitXor] for the enum, with output being Varflags struct, with E being input enum and B being one of the built-in [bitworks] bitsets with correct representation.
  • Generates [TryFrom] implementation for input enum from [bitworks::index::Index] (for the correct Bitset).
  • Generates [core::fmt::Display] for input enum, which just outputs a stringified variant name.
  • Re-exports a type alias for Varflags specific for input enum named as the name of input enum’s name with “Varflags” appended. The re-export will have the same visibility as the enum.