const-assoc

Crates.ioconst-assoc
lib.rsconst-assoc
version0.1.0
created_at2025-02-01 17:49:52.303414+00
updated_at2025-02-01 17:49:52.303414+00
descriptionA const-capable Map type backed by a static array
homepage
repositoryhttps://github.com/yegorvk/const_array_map
max_upload_size
id1538712
size22,408
Yegor Vaskonyan (yegorvk)

documentation

README

const-assoc

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,
}

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

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

cargo fmt