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

Configuration formats

dotcfg keeps the API the same while the file format changes. TOML is enabled by default; JSON and YAML are opt-in Cargo features.

TOML — default

Cargo.toml
[dependencies]
dotcfg = "0.3.0"

DotCfg::new("mytool") selects TOML when the default features are enabled. You can also call .toml() explicitly.

JSON

Cargo.toml
[dependencies]
dotcfg = { version = "0.3.0", features = ["json"] }
Rust
let cfg = DotCfg::new("mytool").json();
// ~/.mytool/config.json

YAML

Cargo.toml
[dependencies]
dotcfg = { version = "0.3.0", features = ["yaml"] }
Rust
let cfg = DotCfg::new("mytool").yaml();
// ~/.mytool/config.yaml

Enable several formats

Cargo features are additive. Enabling JSON does not disable the default TOML feature. If your program needs all three formats, enable JSON and YAML alongside the default.

Cargo.toml
dotcfg = { version = "0.3.0", features = ["json", "yaml"] }

Use your own filename

.filename() accepts the filename without an extension. dotcfg adds the extension that matches the selected format.

Rust
let cfg = DotCfg::new("mytool")
    .json()
    .filename("settings");

// ~/.mytool/settings.json