3 releases (breaking)
0.3.0 | Mar 3, 2024 |
---|---|
0.2.0 | Mar 3, 2024 |
0.1.0 | Mar 3, 2024 |
#1669 in Embedded development
43 downloads per month
60KB
780 lines
EnuMap
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.
Usage
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"
Examples
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!
Dependencies
~155KB