#config #configuration #toml #json #yaml

figment

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

6 releases

0.9.4 Oct 30, 2020
0.9.3 Oct 26, 2020
0.8.1 Oct 10, 2020

#41 in Configuration

Download history 36/week @ 2020-10-09 491/week @ 2020-10-16 1100/week @ 2020-10-23 1603/week @ 2020-10-30 1062/week @ 2020-11-06 1743/week @ 2020-11-13 1358/week @ 2020-11-20

553 downloads per month

MIT/Apache

235KB
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.9", features = ["toml", "env"] }

License

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

Dependencies

~0.2–1MB
~20K SLoC