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
| Type | Keys | When to use |
|---|---|---|
VarMap | Key (compile-time hash via var!) | Fixed names known at compile time |
StrVarMap | &str (FNV-1a at runtime) | Dynamic names from config or user input |
EnumVarMap | E: [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§
- Enum
VarMap - Heterogeneous map keyed by an enum implementing
EnumVarMapKey. - Key
- Opaque key for
VarMap, holding a 64-bit hash. - StrVar
Map - Heterogeneous map keyed by
&str. - Value
- An encoded value and its associated arena borrow.
- Value
Builder - Helper for encoding
VarMapValuetypes into a map arena. - Value
Mut - 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§
- Enum
VarMap Key - Enum key type for
EnumVarMap. - VarMap
Value - Types that can be stored in and read from a varmap.
Derive Macros§
- Enum
VarMap - Derives
EnumVarMapKeyfor a unit enum. - VarMap
Value - Derives
VarMapValuefor aCopystruct or enum.