1 unstable release

0.1.1 Jan 19, 2025
0.1.0 Jan 19, 2025

#1988 in Procedural macros

Download history 194/week @ 2025-01-19 1/week @ 2025-01-26 22/week @ 2025-02-02 4/week @ 2025-02-09

221 downloads per month
Used in const_array_map

MIT/Apache

5KB
75 lines

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

Dependencies

~315–780KB
~18K SLoC