| Crates.io | insert-only-set |
| lib.rs | insert-only-set |
| version | 0.3.1 |
| created_at | 2024-05-10 04:52:46.948416+00 |
| updated_at | 2024-05-10 05:59:17.658026+00 |
| description | A procedural macro to generate insert-only sets from enums |
| homepage | https://github.com/ckoopmann/insert-only-set |
| repository | https://github.com/ckoopmann/insert-only-set |
| max_upload_size | |
| id | 1235695 |
| size | 22,197 |
insert_only_set is a procedural macro to generates thread-safe insert-only sets from enums in Rust.
Under the hood this set is a struct with a OnceLock field for each enum variant.
OnceLockuse 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));
assert!(set.insert(Type::Customer));
assert!(set.contains(Type::Customer));
assert!(!set.contains(Type::Employee));
assert!(set.insert(Type::Employee));
assert!(set.contains(Type::Customer));
assert!(set.contains(Type::Employee));
// Try to insert again, should return false
assert!(!set.insert(Type::Customer));
for variant in set.iter() {
println!("{:?}", variant);
}
}