#config-parser #config-toml #parser #utility #toml-parser #serde

confik

A library for reading application configuration split across multiple sources

17 releases

0.12.0 Oct 21, 2024
0.11.7 Mar 23, 2024
0.11.4 Dec 4, 2023
0.11.3 Nov 12, 2023
0.10.0 Jul 17, 2023

#48 in Configuration

Download history 2100/week @ 2024-08-14 1806/week @ 2024-08-21 2193/week @ 2024-08-28 2207/week @ 2024-09-04 1978/week @ 2024-09-11 2451/week @ 2024-09-18 2818/week @ 2024-09-25 3096/week @ 2024-10-02 2225/week @ 2024-10-09 3273/week @ 2024-10-16 2735/week @ 2024-10-23 2736/week @ 2024-10-30 1416/week @ 2024-11-06 1999/week @ 2024-11-13 2369/week @ 2024-11-20 1805/week @ 2024-11-27

8,111 downloads per month

MIT/Apache

63KB
1.5K 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.7–4.5MB
~91K SLoC