Crates.io | figment-directory |
lib.rs | figment-directory |
version | 0.1.0 |
source | src |
created_at | 2024-05-19 15:19:15.57856 |
updated_at | 2024-05-19 15:19:15.57856 |
description | Figment provider for config values split into multiple files in a directory, working with any format. |
homepage | |
repository | https://github.com/anmolitor/figment-directory |
max_upload_size | |
id | 1244987 |
size | 26,443 |
Figment provider for config values split into multiple files in a directory, working with any Format.
use serde::Deserialize;
use figment::{Figment, providers::{Env, Format, Toml}};
use figment_directory::FormatExt as _;
#[derive(Deserialize)]
struct Config {
database: DatabaseConfig,
pubsub: PubsubConfig
}
#[derive(Deserialize)]
struct DatabaseConfig {
url: String,
}
#[derive(Deserialize)]
struct PubsubConfig {
url: String,
}
let config: Config = Figment::new()
.merge(Toml::directory("config"))
.extract()?;
Directory structure:
# database.toml
url = "some/url"
# pubsub.toml
url = "some/url"
This crate contains the Directory
provider for Figment
, to allow loading
configuration values a directory containing (possibly nested) files in a consistent file format.
It is wrapped around a Format
implementation like figment::providers::Json
or figment::providers::Toml
.
This might be helpful if you have a lot of configuration values and wish to organize it using the file system.
See the documentation for a detailed usage guide and more information.
Add the following to your Cargo.toml
:
[dependencies]
figment = { version = "0.10" }
figment-directory = { version = "0.1" }
figment_directory is licensed under the BSD-3-Clause License