figment 0.10.2

A configuration library so con-free, it's unreal.
Documentation

Figment   ci.svg crates.io docs.rs

Figment is a semi-hierarchical configuration library for Rust so con-free, it's unreal.

use serde::Deserialize;

use figment::{Figment, providers::{Format, Toml, Json, Env}};

#[derive(Deserialize)]
struct Package {
    name: String,
    authors: Vec<String>,
    publish: Option<bool>,
    // ... and so on ...
}

#[derive(Deserialize)]
struct Config {
    package: Package,
    rustc: Option<String>,
    // ... and so on ...
}

let config: Config = Figment::new()
    .merge(Toml::file("Cargo.toml"))
    .merge(Env::prefixed("CARGO_"))
    .merge(Env::raw().only(&["RUSTC", "RUSTDOC"]))
    .join(Json::file("Cargo.json"))
    .extract()?;

See the documentation for a detailed usage guide and information.

Usage

Add the following to your Cargo.toml, enabling the desired built-in providers:

[dependencies]
figment = { version = "0.10", features = ["toml", "env"] }

License

Figment is licensed under either of the following, at your option: