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
toml
host = "google.com"
username = "root"
and the environment contains
sh
PASSWORD=hunter2
Then:
```rust use confik::{Configuration, EnvSource, FileSource};
struct Config { host: String, username: String,
#[confik(secret)]
password: String,
}
fn main() { let config = Config::builder() .overridewith(FileSource::new("config.toml")) .overridewith(EnvSource::new().allowsecrets()) .trybuild() .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.