Crates.io | figment |
lib.rs | figment |
version | 0.10.19 |
source | src |
created_at | 2020-10-10 11:43:02.488221 |
updated_at | 2024-05-17 02:54:57.543501 |
description | A configuration library so con-free, it's unreal. |
homepage | |
repository | https://github.com/SergioBenitez/Figment |
max_upload_size | |
id | 297978 |
size | 323,394 |
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.
Add the following to your Cargo.toml
, enabling the desired built-in providers:
[dependencies]
figment = { version = "0.10", features = ["toml", "env"] }
The following external libraries implement Figment providers:
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.
Figment is licensed under either of the following, at your option: