#data-structure #no-std #enum

no-std enum-map

A map with C-like enum keys represented internally as an array

67 releases (12 stable)

Uses new Rust 2021

2.4.1 Jul 28, 2022
2.3.0 May 29, 2022
2.1.0 Mar 24, 2022
2.0.0-1 Oct 1, 2021
0.2.9 Jul 26, 2017

#21 in Data structures

Download history 21671/week @ 2022-06-10 23848/week @ 2022-06-17 23790/week @ 2022-06-24 19779/week @ 2022-07-01 20207/week @ 2022-07-08 21964/week @ 2022-07-15 24802/week @ 2022-07-22 27482/week @ 2022-07-29 26290/week @ 2022-08-05 26255/week @ 2022-08-12 30586/week @ 2022-08-19 24889/week @ 2022-08-26 19393/week @ 2022-09-02 21935/week @ 2022-09-09 19944/week @ 2022-09-16 16876/week @ 2022-09-23

82,998 downloads per month
Used in 200 crates (36 directly)

MIT/Apache

35KB
738 lines

enum-map

A library providing enum map providing type safe enum array. It is implemented using regular Rust arrays, so using them is as fast as using regular Rust arrays.

This library doesn't provide Minimum Supported Rust Version (MSRV). If you find having MSRV valuable, please use enum-map 0.6 instead.

Examples

#[macro_use]
extern crate enum_map;

use enum_map::EnumMap;

#[derive(Debug, Enum)]
enum Example {
    A,
    B,
    C,
}

fn main() {
    let mut map = enum_map! {
        Example::A => 1,
        Example::B => 2,
        Example::C => 3,
    };
    map[Example::C] = 4;

    assert_eq!(map[Example::A], 1);

    for (key, &value) in &map {
        println!("{:?} has {} as value.", key, value);
    }
}

lib.rs:

An enum mapping type.

It is implemented using an array type, so using it is as fast as using Rust arrays.

Examples

use enum_map::{enum_map, Enum, EnumMap};

#[derive(Debug, Enum)]
enum Example {
    A(bool),
    B,
    C,
}

let mut map = enum_map! {
    Example::A(false) => 0,
    Example::A(true) => 1,
    Example::B => 2,
    Example::C => 3,
};
map[Example::C] = 4;

assert_eq!(map[Example::A(true)], 1);

for (key, &value) in &map {
    println!("{:?} has {} as value.", key, value);
}

Dependencies

~220–710KB
~17K SLoC