#utility #serde #source #parser

confik

A library for reading application configuration split across multiple sources

19 unstable releases (8 breaking)

0.14.0 Apr 22, 2025
0.13.0 Mar 15, 2025
0.12.0 Oct 21, 2024
0.11.7 Mar 23, 2024
0.10.0 Jul 17, 2023

#42 in Configuration

Download history 2715/week @ 2025-01-08 3081/week @ 2025-01-15 2739/week @ 2025-01-22 2847/week @ 2025-01-29 4142/week @ 2025-02-05 3932/week @ 2025-02-12 5849/week @ 2025-02-19 5670/week @ 2025-02-26 4913/week @ 2025-03-05 5634/week @ 2025-03-12 5242/week @ 2025-03-19 6284/week @ 2025-03-26 5806/week @ 2025-04-02 4995/week @ 2025-04-09 4517/week @ 2025-04-16 5670/week @ 2025-04-23

22,316 downloads per month

MIT/Apache

65KB
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–5MB
~101K SLoC