Crates.io | enumap |
lib.rs | enumap |
version | 0.3.0 |
source | src |
created_at | 2024-03-03 12:53:49.124612 |
updated_at | 2024-03-03 19:36:01.210948 |
description | A HashMap and HashSet like interface for enums backed by an array |
homepage | |
repository | https://github.com/Dav1dde/enumap |
max_upload_size | |
id | 1160585 |
size | 62,021 |
HashMap and HashSet like interfaces for enumerations backed by an array.
enumap
is no_std
compatible, dependency and proc macro free for blazingly fast compilation speeds.
This crate is on crates.io and can be
used by adding it to your dependencies in your project's Cargo.toml
.
[dependencies]
enumap = "0.3"
use enumap::{EnumMap, EnumSet};
enumap::enumap! {
/// A beautiful fruit, ready to be sold.
#[derive(Debug)]
enum Fruit {
Orange,
Banana,
Grape,
}
}
// A fruit shop: fruit -> stock.
let mut shop = EnumMap::new();
let mut orders = EnumSet::new();
shop.insert(Fruit::Orange, 100);
shop.insert(Fruit::Banana, 200);
for (fruit, amount) in &shop {
println!("There are {amount} {fruit:?}s in stock!");
}
if !shop.contains_key(Fruit::Grape) {
println!("Sorry no grapes in stock :(");
orders.insert(Fruit::Grape);
}
for fruit in &orders {
println!("{fruit:?} needs to be ordered!");
}
Browse the docs for more examples!