8 breaking releases

new 0.14.0 Apr 22, 2025
0.13.0 Mar 15, 2025
0.12.0 Oct 21, 2024
0.11.1 Dec 4, 2023
0.10.0 Jul 17, 2023

#1249 in Configuration

Download history 1320/week @ 2024-12-31 2361/week @ 2025-01-07 3023/week @ 2025-01-14 2946/week @ 2025-01-21 2819/week @ 2025-01-28 3557/week @ 2025-02-04 4319/week @ 2025-02-11 5975/week @ 2025-02-18 5199/week @ 2025-02-25 4980/week @ 2025-03-04 5581/week @ 2025-03-11 5126/week @ 2025-03-18 6227/week @ 2025-03-25 6584/week @ 2025-04-01 5030/week @ 2025-04-08 3202/week @ 2025-04-15

22,351 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