Skip to main content

BitRole

Derive Macro BitRole 

Source
#[derive(BitRole)]
{
    // Attributes available to this derive:
    #[bitrole]
}
Expand description

Derives the BitRole trait for role-based access control.

Automatically implements BitRole for enums with unit variants only. Each variant is assigned a bit position (0, 1, 2, …) for role masking.

§Requirements

  • Only unit variants allowed (no tuple or struct variants)
  • Explicit discriminants must be > 0
  • Enum must derive Copy, Debug, and implement IntoEnumIterator (from strum)

§Example

#[derive(Debug, Copy, Clone, BitRole, EnumIter)]
enum UserRole {
    Viewer = 1,
    Editor = 2,
    Admin = 3,
}