Crate enumset [] [src]

A library for defining enums that can be used in compact bit sets.

It supports enums up to 64 variants on stable Rust, and up to 128 variants on nightly Rust with the nightly feature enabled.

Defining enums for use with EnumSet

Enums to be used with EnumSet should be defined through the enum_set_type! macro:

enum_set_type! {
    /// Documentation for the enum
    pub enum Enum {
        A, B, C, D, E, F, G,
        #[doc(hidden)] __NonExhaustive,

Working with EnumSets

EnumSets can be constructed via EnumSet::new() like a normal set. In addition, enum_set_type! creates operator overloads that allow you to create EnumSets like so:

let new_set = Enum::A | Enum::C | Enum::G;
assert_eq!(new_set.len(), 3);

The enum_set! macro also allows you to create constant EnumSets:

const CONST_SET: EnumSet<Enum> = enum_set!(Enum, Enum::A | Enum::B);
assert_eq!(CONST_SET, Enum::A | Enum::B);

Mutable operations on the EnumSet otherwise work basically as expected:

let mut set = EnumSet::new();
set.insert_all(Enum::E | Enum::G);
assert_eq!(set, Enum::A | Enum::E | Enum::G);



Creates a EnumSet literal, which can be used in const contexts.


Defines enums which can be used with EnumSet.



An efficient set type for enums created with the enum_set_type! macro.


The iterator used by EnumSet.