enumap

Crates.ioenumap
lib.rsenumap
version0.3.0
sourcesrc
created_at2024-03-03 12:53:49.124612
updated_at2024-03-03 19:36:01.210948
descriptionA HashMap and HashSet like interface for enums backed by an array
homepage
repositoryhttps://github.com/Dav1dde/enumap
max_upload_size
id1160585
size62,021
David Herberth (Dav1dde)

documentation

README

EnuMap

Crates.io License Build Status docs.rs

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!

Commit count: 0

cargo fmt