A library for defining enums that can be used in compact bit sets. It supports enums up to 128 variants, and has a macro to use these sets in constants.
For serde support, enable the serde
feature.
Defining enums for use with EnumSet
Enums to be used with [EnumSet
] should be defined using #[derive(EnumSetType)]
:
# use *;
Working with EnumSets
EnumSets can be constructed via [EnumSet::new()
] like a normal set. In addition,
#[derive(EnumSetType)]
creates operator overloads that allow you to create EnumSets like so:
# use *;
#
let new_set = A | C | G;
assert_eq!;
All bitwise operations you would expect to work on bitsets also work on both EnumSets and
enums with #[derive(EnumSetType)]
:
# use *;
#
// Intersection of sets
assert_eq!;
assert_eq!;
assert_eq!;
// Symmetric difference of sets
assert_eq!;
assert_eq!;
// Difference of sets
assert_eq!;
// Complement of sets
assert_eq!;
The [enum_set!
] macro allows you to create EnumSets in constant contexts:
# use *;
#
const CONST_SET: = enum_set!;
assert_eq!;
Mutable operations on the [EnumSet
] otherwise work basically as expected:
# use *;
#
let mut set = new;
set.insert;
set.insert_all;
assert!;
assert!;
assert_eq!;