confik-macros

Crates.ioconfik-macros
lib.rsconfik-macros
version0.11.1
sourcesrc
created_at2023-07-12 13:57:42.788166
updated_at2023-12-04 17:00:00.172286
descriptionMacros for confik
homepage
repositoryhttps://github.com/x52dev/confik
max_upload_size
id914534
size59,206
Rob Ede (robjtede)

documentation

README

confik

crates.io Documentation MIT or Apache 2.0 licensed
Version dependency status Download

This crate provides a macro for creating configuration/settings structures and functions to read them from files and the environment.

Example

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(),
        }
    );
}

License

This project is licensed under either of

  • Apache License, Version 2.0
  • MIT License

at your option.

Commit count: 167

cargo fmt