tomldir
tomldir is a small, opinionated Rust crate for loading TOML configuration files into map-based data structures, optimized for runtime access, flattening, and configuration composition.
Usage
Add to Cargo.toml:
[]
= "0.1"
# Optional: for order-preserving keys
= "2.0"
Basic Usage
use Config;
Advanced: Preserving Order with IndexMap
If you need to iterate over keys in the order they were defined (e.g., for help text generation or consistent output), use IndexMap.
use ;
use IndexMap;
You can get an iterator over all flattened key-value pairs as strings:
for in cfg.flatten
Or collect them into a specific map (like HashMap<String, String>) using flatten_into():
let flat: = cfg.flatten_into;
Or flatten into any custom type using flatten_into():
use BTreeMap;
// Flatten to BTreeMap (sorted keys)
let flat_sorted: = cfg.flatten_into;
// Flatten to Vec
let flat_vec: = cfg.flatten_into;
Features
- TOML-only: Built directly on
toml::Value. - Map-first: Stores data as
HashMapby default, but swapable forIndexMaporBTreeMap. - Thread-safe: Designed for
Arcusage and concurrency. - Deterministic Flattening: Nested tables become dot-separated keys.
License
MIT