#data-structure #enum #no_std

macro no-std enum-map-derive

Macros 1.1 implementation of #[derive(Enum)]

20 releases

0.4.3 Sep 10, 2019
0.4.1 Jan 18, 2019
0.4.0 Jun 6, 2018
0.2.4 Sep 6, 2017
0.2.2 May 18, 2017

#95 in Data structures

Download history 789/week @ 2019-06-29 1099/week @ 2019-07-06 917/week @ 2019-07-13 997/week @ 2019-07-20 681/week @ 2019-07-27 572/week @ 2019-08-03 970/week @ 2019-08-10 1074/week @ 2019-08-17 1004/week @ 2019-08-24 950/week @ 2019-08-31 1416/week @ 2019-09-07 1080/week @ 2019-09-14 964/week @ 2019-09-21 967/week @ 2019-09-28 1031/week @ 2019-10-05

3,937 downloads per month
Used in 38 crates (2 directly)

MIT/Apache

5KB
88 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.

If you are using Rust 1.35 or older, you may want to use enum-map 0.5 instead, as enum-map 0.6 requires Rust 1.36.

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:

Procedural macro implementing #[derive(Enum)]

This is supposed to used with enum-map crate, which provides the actual usage documentation.

Dependencies

~0.6–0.8MB
~20K SLoC