22 releases

0.10.15 Mar 16, 2024
0.10.13 Dec 31, 2023
0.10.12 Oct 30, 2023
0.10.10 Jun 2, 2023
0.9.4 Oct 30, 2020

#3 in Configuration

Download history 47001/week @ 2023-12-07 47245/week @ 2023-12-14 27908/week @ 2023-12-21 34881/week @ 2023-12-28 49172/week @ 2024-01-04 55065/week @ 2024-01-11 64898/week @ 2024-01-18 56406/week @ 2024-01-25 57653/week @ 2024-02-01 62709/week @ 2024-02-08 58890/week @ 2024-02-15 56340/week @ 2024-02-22 60791/week @ 2024-02-29 60225/week @ 2024-03-07 66001/week @ 2024-03-14 50299/week @ 2024-03-21

247,453 downloads per month
Used in 423 crates (129 directly)

MIT/Apache

290KB
4K 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"] }

Third-Party Providers

The following external libraries implement Figment providers:

  • figment_file_provider_adapter

    Wraps existing providers. For any key ending in _FILE (configurable), emits a key without the _FILE suffix with a value corresponding to the contents of the file whose path is the original key's value.

Please submit a pull request to add your library to this list.

License

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

Dependencies

~0.1–11MB
~102K SLoC