varmap 0.1.1

Fast, heterogeneous key-value maps for Rust. Store mixed types (integers, strings, bytes, custom structs) under a single key namespace, with compile-time keys, runtime strings, or enum variants. Arena-backed for zero-copy reads of strings and byte slices.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::*;

impl VarMapValue for bool {
    type Decoded<'a> = bool;

    const TYPE_ID: u32 = 0;

    fn to_value<'a>(&self, builder: &'a mut ValueBuilder<'a>) -> Value<'a> {
        Value::new(ValueKind::Bool(*self), builder.arena())
    }

    fn from_value<'a>(value: &Value<'a>) -> Option<bool> {
        match value.kind() {
            ValueKind::Bool(b) => Some(*b),
            _ => None,
        }
    }
}