Expand description
§dotcfg
Flexible config management for Rust applications.
- Choose between
~/.toolname/,~/.config/toolname/, or a custom directory - TOML, JSON or YAML format (feature-gated)
- Load, save, get, set — full or per-key
- Typed per-key access with
get_as/set_val(numbers, bools, arrays, structs) - Flat (
username) and nested (user.username) key support - Opt-in environment variable overrides via
with_env_prefix - Returns
Noneif config doesn’t exist — no magic auto-create unless you want it
§Features
toml(default) — enables TOML supportjson— enables JSON supportyaml— enables YAML support
§Example
use dotcfg::DotCfg;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Default)]
struct MyConfig {
username: String,
port: u16,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let cfg = DotCfg::new("mytool");
// Load — returns None if file doesn't exist
let config: Option<MyConfig> = cfg.load()?;
// Save
cfg.save(&MyConfig { username: "john".into(), port: 8080 })?;
// Get a single key
let val = cfg.get("username")?;
// Set a single key
cfg.set("username", "jane")?;
// Typed per-key access — no string round trip
cfg.set_val("port", 8080u16)?;
let port: u16 = cfg.get_as("port")?;
Ok(())
}Modules§
- error
- Error types for
dotcfg.
Structs§
- DotCfg
- The main dotcfg handle. Create one per app.
Enums§
- DirStrategy
- Where the config folder lives
- Format
- Config file format