#yaml-config #toml #json

figment

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

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

#3 in Configuration

Download history 92599/week @ 2024-12-16 42871/week @ 2024-12-23 51934/week @ 2024-12-30 101490/week @ 2025-01-06 106262/week @ 2025-01-13 107734/week @ 2025-01-20 126293/week @ 2025-01-27 142434/week @ 2025-02-03 138406/week @ 2025-02-10 124841/week @ 2025-02-17 148449/week @ 2025-02-24 153180/week @ 2025-03-03 167481/week @ 2025-03-10 155423/week @ 2025-03-17 150311/week @ 2025-03-24 144389/week @ 2025-03-31

624,648 downloads per month
Used in 775 crates (189 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–9.5MB
~109K SLoC