enum_dict
A Rust library for efficient enum-indexed dictionaries.
Installation
Add to your Cargo.toml:
[]
= { = "0.7", = ["full"] }
Quick Start
use ;
// `RequiredDict` - all keys must have values
let mut colors = required_dict! ;
// Direct indexing - no `.get()` needed!
println!;
// Mutable access
colors = "#FF0001";
// `OptionalDict` - keys may or may not have values
let favorite_colors = optional_dict! ;
// Returns `Option<&str>`
if let Some = favorite_colors
Serde Support
With the serde feature enabled, RequiredDict and OptionalDict can be serialized and deserialized using serde:
use ;
use ;
Extra keys in the serialized data are ignored during deserialization.
Why enum_dict?
Compared to traditional HashMap approach, enum_dict uses Vec under the hood, allowing for:
- Direct Indexing: Access values with
dict[key]instead ofdict.get(&key). - Performance: Faster access times due to contiguous memory layout.
- Type Safety: Compile-time checks ensure all enum variants are handled.
- Simplicity: Less boilerplate code for common use cases.