7 releases (breaking)

0.11.1 Dec 4, 2023
0.11.0 Oct 20, 2023
0.10.0 Jul 17, 2023
0.9.0 Jul 13, 2023
0.0.1 Jul 12, 2023

#851 in Configuration

Download history 1430/week @ 2023-12-18 2456/week @ 2023-12-25 824/week @ 2024-01-01 1313/week @ 2024-01-08 1106/week @ 2024-01-15 1349/week @ 2024-01-22 902/week @ 2024-01-29 1475/week @ 2024-02-05 2226/week @ 2024-02-12 1026/week @ 2024-02-19 1915/week @ 2024-02-26 1467/week @ 2024-03-04 850/week @ 2024-03-11 839/week @ 2024-03-18 777/week @ 2024-03-25 999/week @ 2024-04-01

3,468 downloads per month
Used in confik

MIT/Apache

35KB
743 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
~25K SLoC