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.jsonYAML
Cargo.toml
[dependencies]
dotcfg = { version = "0.3.0", features = ["yaml"] }Rust
let cfg = DotCfg::new("mytool").yaml();
// ~/.mytool/config.yamlEnable 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