#config #configuration #toml #json #yaml

figment

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

10 releases

0.10.3 Feb 14, 2021
0.10.2 Jan 14, 2021
0.10.0 Dec 22, 2020
0.9.4 Oct 30, 2020
0.8.1 Oct 10, 2020

#15 in Configuration

Download history 1147/week @ 2020-11-07 1710/week @ 2020-11-14 1309/week @ 2020-11-21 1148/week @ 2020-11-28 1536/week @ 2020-12-05 1657/week @ 2020-12-12 1658/week @ 2020-12-19 1063/week @ 2020-12-26 1519/week @ 2021-01-02 3323/week @ 2021-01-09 2699/week @ 2021-01-16 2901/week @ 2021-01-23 2561/week @ 2021-01-30 3462/week @ 2021-02-06 3154/week @ 2021-02-13 3061/week @ 2021-02-20

8,752 downloads per month

MIT/Apache

245KB
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