#arena #enums #stored #storage #enumeration #derive #enums-id-arena

enums_arena

enums_arena is an arena that enums can be stored efficiently

4 releases

0.1.4 Apr 5, 2023
0.1.3 Apr 2, 2023
0.1.2 Apr 2, 2023
0.1.1 Apr 1, 2023
0.1.0 Apr 1, 2023

#1490 in Rust patterns

Download history 18/week @ 2024-07-30 1/week @ 2024-09-17 7/week @ 2024-09-24

60 downloads per month

MIT license

16KB
295 lines

Arena, fast and efficient storage enumeration


lib.rs:

enums_arena

enums_arena is an arena that enums can be stored efficiently

usage:

#[derive(PartialEq, Debug, Clone, Default)]
struct Click {
    x: i32,
    y: i32,
}
#[derive(enums_arena_derive::EnumsIdArena, PartialEq, Debug)]
enum Event {
    Click(Click),
    Tick(f32),
    Close,
}

let mut arena = EventIdArena::<u32, ()>::default();
let id = arena.alloc_click(Click::default());
arena.alloc_tick(1f32);
arena.alloc_close();

assert_eq!(arena.get(id), Some(Event::Click(Click::default())));
arena.clear();
assert_eq!(arena.get(id), None);

Dependencies

~0.6–1MB
~21K SLoC