Crates.io | conf_from_env |
lib.rs | conf_from_env |
version | 0.1.0 |
source | src |
created_at | 2022-12-04 00:18:36.863132 |
updated_at | 2022-12-04 00:18:36.863132 |
description | Configurations and secrets defined in structs are automatically read from environment variables. |
homepage | https://github.com/doheide/conf_from_env |
repository | https://github.com/doheide/conf_from_env |
max_upload_size | |
id | 729317 |
size | 3,397 |
This library automatically reads configurations from environment variables. The configuration is defined in one struct for configuration values and in one struct for secrets. The environment variables are expected to have the same name as the struct attributes in uppercase.
LOG_LEVEL=info
REDIS_HOST=127.0.0.1
REDIS_USER=lala
REDIS_PASSWORD=lili
pub struct Config {
pub log_level: String,
pub redis_host: String,
pub redis_user: String,
timeout: u32
}
#[derive(SetStructFromEnv, Clone)]
pub struct Secrets {
pub redis_password: String,
}
pub type CoSe = ConfigAndSecrets<Config, Secrets>;
fn main() {
let cose = CoSe::from_env();
println!("config and secrets: {:?}", cose);
}