26 releases

0.10.19 May 17, 2024
0.10.15 Mar 16, 2024
0.10.13 Dec 31, 2023
0.10.12 Oct 30, 2023
0.9.4 Oct 30, 2020

#2 in Configuration

Download history 77054/week @ 2024-09-19 83859/week @ 2024-09-26 89121/week @ 2024-10-03 85941/week @ 2024-10-10 97670/week @ 2024-10-17 100049/week @ 2024-10-24 94073/week @ 2024-10-31 89494/week @ 2024-11-07 95385/week @ 2024-11-14 102767/week @ 2024-11-21 101443/week @ 2024-11-28 104177/week @ 2024-12-05 98745/week @ 2024-12-12 59927/week @ 2024-12-19 41151/week @ 2024-12-26 64667/week @ 2025-01-02

285,354 downloads per month
Used in 684 crates (181 directly)

MIT/Apache

305KB
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–9MB
~104K SLoC