#configuration-management #loader #zero-boilerplate

configit

Zero-boilerplate configuration management in Rust

8 releases

0.3.1 Jan 23, 2022
0.3.0 Jan 21, 2022
0.2.0 Jan 16, 2022
0.1.4 Jan 16, 2022

#562 in Configuration

27 downloads per month

MIT/Apache

8KB
75 lines

configit

Zero-boilerplate configuration management in Rust

Installation

cargo add configit

usage

config.toml

host = "127.0.0.1"
port = 8888

src/main.rs

use serde::{Deserialize, Serialize};
use configit::Loader;

#[derive(Debug, Deserialize)]
pub struct AppConfig {
    pub host: String,
    pub port: u16,
}

fn main() {
    let config = AppConfig::load("config.toml").expect("couldn't load `config.toml` file");
    println!("config: {config:?}"); // config: AppConfig { host: "127.0.0.1", port: 8888 }
}

lib.rs:

Zero-boilerplate configuration management

Usage

use serde_derive::Deserialize;
use configit::Loader;

#[derive(Debug, Deserialize)]
pub struct AppConfig {
    host: String,
    port: u16,
}

let config = AppConfig::load("config.toml").expect("couldn't load `config.toml` file");
println!("config: {config:?}");

Dependencies

~0.4–1.3MB
~29K SLoC