8 releases (breaking)

0.12.0 Oct 21, 2024
0.11.1 Dec 4, 2023
0.11.0 Oct 20, 2023
0.10.0 Jul 17, 2023
0.0.1 Jul 12, 2023

#43 in #config-toml

Download history 2030/week @ 2024-07-29 1923/week @ 2024-08-05 2065/week @ 2024-08-12 1835/week @ 2024-08-19 1930/week @ 2024-08-26 2308/week @ 2024-09-02 2110/week @ 2024-09-09 1903/week @ 2024-09-16 2801/week @ 2024-09-23 3112/week @ 2024-09-30 2328/week @ 2024-10-07 2918/week @ 2024-10-14 2955/week @ 2024-10-21 2573/week @ 2024-10-28 2792/week @ 2024-11-04 763/week @ 2024-11-11

9,105 downloads per month
Used in confik

MIT/Apache

35KB
742 lines

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.

Dependencies

~0.6–1MB
~23K SLoC