#data-structure #no-std #enum

no-std enum-map

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

53 releases (2 stable)

new 1.1.0 May 4, 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

#26 in Data structures

Download history 6612/week @ 2021-01-14 7531/week @ 2021-01-21 6935/week @ 2021-01-28 6733/week @ 2021-02-04 7051/week @ 2021-02-11 7417/week @ 2021-02-18 7948/week @ 2021-02-25 7603/week @ 2021-03-04 7281/week @ 2021-03-11 7886/week @ 2021-03-18 6782/week @ 2021-03-25 6468/week @ 2021-04-01 8337/week @ 2021-04-08 9210/week @ 2021-04-15 12378/week @ 2021-04-22 10907/week @ 2021-04-29

34,947 downloads per month
Used in 104 crates (20 directly)

MIT/Apache

28KB
594 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.9MB
~21K SLoC