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

confik

A library for reading application configuration split across multiple sources

18 releases

0.13.0 Mar 15, 2025
0.12.0 Oct 21, 2024
0.11.8 Sep 20, 2024
0.11.7 Mar 23, 2024
0.10.0 Jul 17, 2023

#38 in Configuration

Download history 2049/week @ 2024-12-05 1708/week @ 2024-12-12 1117/week @ 2024-12-19 302/week @ 2024-12-26 1730/week @ 2025-01-02 2940/week @ 2025-01-09 3052/week @ 2025-01-16 2864/week @ 2025-01-23 2679/week @ 2025-01-30 4221/week @ 2025-02-06 4537/week @ 2025-02-13 6129/week @ 2025-02-20 5417/week @ 2025-02-27 5230/week @ 2025-03-06 4945/week @ 2025-03-13 4459/week @ 2025-03-20

21,504 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–5MB
~100K SLoC