dotcfg 0.3.0 is outCustom directories and project config discovery are now available.See what’s new →
dotcfg
Star on GitHub
Core API

Key access

You do not always need to deserialize and rewrite the whole config. dotcfg can read or update one key while preserving the rest of the file.

Strings with get() and set()

Rust
cfg.set("username", "tayo")?;
let username = cfg.get("username")?;

set() creates the file and parent directory if necessary. When a file already exists, other keys are preserved.

Nested keys

Use dot-separated paths for nested values. Intermediate maps/tables are created when writing a nested key.

Rust
cfg.set("user.name", "tayo")?;
let name = cfg.get("user.name")?;

Typed values with get_as()

get() returns a string. When the value is naturally a number, boolean, list, or another Serde-compatible type, ask dotcfg for that Rust type directly.

Rust
let port: u16 = cfg.get_as("port")?;
let plugins: Vec<String> = cfg.get_as("plugins")?;
let auto_update: bool = cfg.get_as("features.auto_update")?;

The value is deserialized from the config format's native value representation rather than being converted to a string and parsed again.

Typed writes with set_val()

Rust
cfg.set_val("port", 8080u16)?;
cfg.set_val("plugins", vec!["fmt", "lint"])?;
cfg.set_val("features.auto_update", true)?;

This matters because set("port", "8080") is a string-oriented write, while set_val("port", 8080u16) stores a native numeric value.