#data-structure #no-std #enum

no-std enum-map

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

54 releases (3 stable)

1.1.1 May 16, 2021
1.0.0 Mar 28, 2021
0.6.4 Oct 27, 2020
0.6.2 Dec 20, 2019
0.2.9 Jul 26, 2017

#24 in Data structures

Download history 8500/week @ 2021-04-06 8645/week @ 2021-04-13 11201/week @ 2021-04-20 12822/week @ 2021-04-27 11509/week @ 2021-05-04 11875/week @ 2021-05-11 10225/week @ 2021-05-18 7787/week @ 2021-05-25 10937/week @ 2021-06-01 9464/week @ 2021-06-08 11530/week @ 2021-06-15 11885/week @ 2021-06-22 11446/week @ 2021-06-29 11134/week @ 2021-07-06 11386/week @ 2021-07-13 10400/week @ 2021-07-20

37,660 downloads per month
Used in 113 crates (21 directly)

MIT/Apache

32KB
658 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,
    B,
    C,
}

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);
}

Dependencies

~0.3–0.8MB
~20K SLoC