Multi-source configuration library for Rust.

Overview

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.

You might also like...
Alpha Hyprland/Hyprpaper/Hypr configuration file parser

Hyprland/Hyprpaper/Hypr configuration file parser [maintainer=@yavko]

Ryan: a configuration language for the practical programmer
Ryan: a configuration language for the practical programmer

Ryan: a configuration language for the practical programmer Say hello to Ryan! Ryan is a minimal programming language that produces JSON (and therefor

Neovim Configuration Manager (Swap/Backup/Try Configurations Easily)
Neovim Configuration Manager (Swap/Backup/Try Configurations Easily)

ncm-rs Neovim Configuration Manager (Swap/Backup/Try Configurations Easily) I created this package because I wanted to try out Lazyvim (which is why i

A monitor (service) for your monitor (display). Intercepts window behaviour when monitor configuration changes.

Mon-Mon A monitor (service) for your monitor (display). Listens for changes to display configuration (e.g. plugging in an additional screen) and allow

Multi-Architecture Code Emission Library

macel Multi-Architecture Code Emission Library (macel) is a library which implements a low-level intermediate representation meant to expose on machin

Show unused code from multi-crate Rust projects

Warnalyzer Remove unused code from multi-crate Rust projects. The dead_code lint family of rustc is limited to one crate only and thus can't tell whet

CarLI is a framework for creating single-command and multi-command CLI applications in Rust

CarLI is a framework for creating single-command and multi-command CLI applications in Rust. The framework provides error and IO types better suited for the command line environment, especially in cases where unit testing is needed.

Concurrent and multi-stage data ingestion and data processing with Rust+Tokio

TokioSky Build concurrent and multi-stage data ingestion and data processing pipelines with Rust+Tokio. TokioSky allows developers to consume data eff

A multi-page fuzzy launcher for your terminal, written in Rust.
A multi-page fuzzy launcher for your terminal, written in Rust.

fr33zmenu A multi-page fuzzy launcher for your terminal, written in Rust. Supports theming and multiple keybind schemes, including basic vim keybinds.

Comments
  • Better handling

    Better handling

    • ~Make tests run (the previous directory meant they weren't picked up)~ (upstreamed to main)
    • Fix the Option behaviour, it can now have #[config(default = ...)] set.
    • Don't default if you have an error in your configuration, previously partial configuration would be overwritten by the defaults, now it appropriately returns an error

    Examples provided in the CHANGELOG

    Also, not sure how you want to fix this (is there a good way to keep it up to date?) but the links in the README are outdated, e.g. the docs link goes to 0.7. Happy to manually bump in this MR, if that's the way to handle it.

    opened by tenuous-guidance 1
Releases(confik-v0.9.0)
  • confik-v0.9.0(Jul 13, 2023)

  • confik-v0.8.0(Jul 13, 2023)

    • Attributes that receive expressions (default and from) now need to be unquoted, e.g.:

      - struct Config { #[config(default = "\"Hello World\"") param: String }
      + struct Config { #[config(default = "Hello World") param: String }
      
      - struct Config { #[config(default = "5_usize") param: usize }
      + struct Config { #[config(default = 5_usize) param: usize }
      
    Source code(tar.gz)
    Source code(zip)
Owner
Rob Ede
Full-stack Web Developer | Typography, UX & Security Enthusiast | Rust + TypeScript | Lead @actix | Core @deps-rs
Rob Ede
H2O Open Source Kubernetes operator and a command-line tool to ease deployment (and undeployment) of H2O open-source machine learning platform H2O-3 to Kubernetes.

H2O Kubernetes Repository with official tools to aid the deployment of H2O Machine Learning platform to Kubernetes. There are two essential tools to b

H2O.ai 16 Nov 12, 2022
Rust API Server: A versatile template for building RESTful interfaces, designed for simplicity in setup and configuration using the Rust programming language.

RUST API SERVER Introduction Welcome to the Rust API Server! This server provides a simple REST interface for your applications. This README will guid

Harry Nguyen 3 Feb 25, 2024
A CLI to easily switch between multiple Neovim configuration environments, written in Rust

Neovim Configuration Switcher Neovim Configuration Switcher (short nvims) is a CLI to easily switch between multiple Neovim configuration environments

Nhan Pham 3 Mar 30, 2024
A very opinionated, zero-configuration shell prompt

A very opinionated, zero-configuration shell prompt

amy null 8 Nov 4, 2021
Application microframework with command-line option parsing, configuration, error handling, logging, and shell interactions

Abscissa is a microframework for building Rust applications (either CLI tools or network/web services), aiming to provide a large number of features w

iqlusion 524 Dec 26, 2022
A command line tool for easily generating multiple versions of a configuration file from a single template

MultiConf A command line tool for easily generating multiple versions of a configuration file from a single template. Why? I'm a big fan of the i3 win

Ian Clarke 4 Dec 10, 2022
CLI application to run clang-format on a set of files specified using globs in a JSON configuration file.

run_clang_format CLI application for running clang-format for an existing .clang-format file on a set of files, specified using globs in a .json confi

martin 6 Dec 16, 2022
Set Shell Environment Variables across multiple shells with a single configuration file.

Xshe – Cross-Shell Environment Vars xshe allows for setting Shell Environment Variables across multiple shells with a single TOML configuration file.

Ethan Kinnear 9 Dec 16, 2022
CLI application to run clang-tidy on a set of files specified using globs in a JSON configuration file.

run-clang-tidy CLI application for running clang-tidy for an existing .clang-tidy file on a set of files, specified using globs in a .json configurati

martin 7 Nov 4, 2022
WIP GUI for NixOS documentation + configuration

nixos-druid Highly experimental GUI for NixOS. For now I expect to frequently make large changes and break stuff whenever I'm working on this. Screens

Sybrand Aarnoutse 6 Aug 23, 2022