Crate const_assoc

Crate const_assoc 

Source
Expand description

A no_std-compatible, const-capable associative array with minimal or no runtime overhead.

Currently, keys are limited to enums with a primitive representation. In the future, it might be possible to support other types, possibly at the expense of not exposing const-qualified methods for these key types or some runtime overhead.

§Example

use const_assoc::{assoc, PrimitiveEnum};

#[repr(u8)]
#[derive(Copy, Clone, PrimitiveEnum)]
enum Letter {
    A,
    B,
    C,
}

let letters = assoc! {
    Letter::A => 'a',
    Letter::B => 'b',
    Letter::C => 'c',
};

assert_eq!(letters[Letter::A], 'a');
assert_eq!(letters[Letter::C], 'c');

Macros§

assoc
Provides an easy, const-friendly way to construct a new Assoc instance.

Structs§

Assoc
Associates keys with values with minimal or no runtime overhead.
PrimitiveEnumLayout
Describes the layout of an enum with a #[repr(primitive_type)] attribute.

Traits§

ConstDefault
Implements a compilation time default value for the implemented type.
PrimitiveEnum
Indicates that Self is a primitive enum type, meaning that it is an enum with a #[repr(primitive_type)] attribute.

Derive Macros§

PrimitiveEnum