#config #configuration #toml #json #yaml

figment

A configuration library so con-free, it’s unreal

13 releases

0.10.6 Jun 25, 2021
0.10.5 Apr 2, 2021
0.10.4 Mar 31, 2021
0.10.3 Feb 14, 2021
0.8.1 Oct 10, 2020

#7 in Configuration

Download history 3442/week @ 2021-04-05 4432/week @ 2021-04-12 4344/week @ 2021-04-19 4274/week @ 2021-04-26 3560/week @ 2021-05-03 4601/week @ 2021-05-10 4412/week @ 2021-05-17 5922/week @ 2021-05-24 4969/week @ 2021-05-31 7541/week @ 2021-06-07 6873/week @ 2021-06-14 6992/week @ 2021-06-21 7456/week @ 2021-06-28 8394/week @ 2021-07-05 9448/week @ 2021-07-12 10258/week @ 2021-07-19

21,510 downloads per month
Used in 21 crates (5 directly)

MIT/Apache

255KB
3.5K SLoC

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:

Dependencies

~0.2–0.9MB
~19K SLoC