#config-toml #utility #parser #serde #derive-debug #debugging

confik

A library for reading application configuration split across multiple sources

15 releases (5 breaking)

0.11.7 Mar 23, 2024
0.11.5 Jan 30, 2024
0.11.4 Dec 4, 2023
0.11.3 Nov 12, 2023
0.10.0 Jul 17, 2023

#50 in Configuration

Download history 1299/week @ 2024-01-05 1314/week @ 2024-01-12 1226/week @ 2024-01-19 931/week @ 2024-01-26 1151/week @ 2024-02-02 2547/week @ 2024-02-09 1415/week @ 2024-02-16 1895/week @ 2024-02-23 1375/week @ 2024-03-01 1038/week @ 2024-03-08 453/week @ 2024-03-15 1098/week @ 2024-03-22 1023/week @ 2024-03-29 966/week @ 2024-04-05 1246/week @ 2024-04-12 1823/week @ 2024-04-19

5,231 downloads per month

MIT/Apache

62KB
1K SLoC

confik

crates.io Documentation dependency status MIT or Apache 2.0 licensed
CI codecov Version 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

~2.8–4.5MB
~97K SLoC