Crates.io | confik |
lib.rs | confik |
version | 0.12.0 |
source | src |
created_at | 2023-07-12 12:46:08.134555 |
updated_at | 2024-10-21 13:02:11.798638 |
description | A library for reading application configuration split across multiple sources |
homepage | |
repository | https://github.com/x52dev/confik |
max_upload_size | |
id | 914477 |
size | 152,392 |
confik
This crate provides a macro for creating configuration/settings structures and functions to read them from files and the environment.
Assume that config.toml
contains
host = "google.com"
username = "root"
and the environment contains
PASSWORD=hunter2
Then:
use confik::{Configuration, EnvSource, FileSource};
#[derive(Debug, PartialEq, Configuration)]
struct Config {
host: String,
username: String,
#[confik(secret)]
password: String,
}
fn main() {
let config = Config::builder()
.override_with(FileSource::new("config.toml"))
.override_with(EnvSource::new().allow_secrets())
.try_build()
.unwrap();
assert_eq!(
config,
Config {
host: "google.com".to_string(),
username: "root".to_string(),
password: "hunter2".to_string(),
}
);
}
This project is licensed under either of
at your option.