#[derive(InsertOnlySet)]
Expand description
A procedural macro to generate an insert-only set for any enum.
This macro generates a struct with insert
, contains
, and iter
methods for an enum.
The struct uses OnceLock
for thread-safe, one-time insertion of enum variants.
ยงExamples
use insert_only_set::InsertOnlySet;
#[derive(InsertOnlySet, Debug, PartialEq)]
pub enum Type {
Customer,
Employee,
}
fn main() {
let set = Type::InsertOnlySet();
assert!(!set.contains(Type::Customer));
assert!(!set.contains(Type::Employee));
set.insert(Type::Customer);
assert!(set.contains(Type::Customer));
assert!(!set.contains(Type::Employee));
set.insert(Type::Employee);
assert!(set.contains(Type::Customer));
assert!(set.contains(Type::Employee));
for variant in set.iter() {
println!("{:?}", variant);
}
}