Skip to main content

Crate varmap

Crate varmap 

Source
Expand description

Heterogeneous, typed key–value maps for Rust.

Each key holds one value of a known type. Values use a compact 16-byte representation; strings, byte slices, and some large types are stored in a per-map arena so reads can return &str and &[u8] without allocating.

§Map types

TypeKeysWhen to use
VarMapKey (compile-time hash via var!)Fixed names known at compile time
StrVarMap&str (FNV-1a at runtime)Dynamic names from config or user input
EnumVarMapE: [EnumVarMapKey]Closed set of keys as an enum

§Usage model

VarMap is aimed at write once, read many workloads. The arena is append-only: overwriting a key replaces the map entry but does not free a previous arena allocation. Prefer setting each key once, then reading often. Call VarMap::clear, StrVarMap::clear, or EnumVarMap::clear to reset a map between logical snapshots; clear retains allocated capacity for later writes.

§Supported values

Built-in types: integers, floats, bool, char, &str, &[u8], and IP address types. Strings and byte slices up to 14 bytes are stored inline; longer payloads use the arena.

Custom Copy types (alignment 1–16) can use #[derive(VarMapValue)].

§Examples

use varmap::StrVarMap;

let mut map = StrVarMap::new();
map.set("port", 8080u16);
map.set("host", "localhost");

assert_eq!(map.get_u16("port"), Some(8080));
assert_eq!(map.get_str("host"), Some("localhost"));

Macros§

var
Expands a string literal to varmap::Key::new(<fnv1a hash>).

Structs§

EnumVarMap
Heterogeneous map keyed by an enum implementing EnumVarMapKey.
Key
Opaque key for VarMap, holding a 64-bit hash.
StrVarMap
Heterogeneous map keyed by &str.
Value
An encoded value and its associated arena borrow.
ValueBuilder
Helper for encoding VarMapValue types into a map arena.
ValueMut
Mutable view over a stored [ValueKind] and its arena.
VarMap
Heterogeneous map keyed by Key.

Enums§

MemAlign
Alignment bucket for data written into a map arena.

Traits§

EnumVarMapKey
Enum key type for EnumVarMap.
VarMapValue
Types that can be stored in and read from a varmap.

Derive Macros§

EnumVarMap
Derives EnumVarMapKey for a unit enum.
VarMapValue
Derives VarMapValue for a Copy struct or enum.