#json-toml #toml #yaml #loader #json #env-var

configloader-676

A library for loading configuration files (JSON, TOML, YAML) into Rust structs with environment variable overrides and validation

1 unstable release

new 0.1.0 Mar 20, 2025

#705 in Configuration

MIT/Apache

13KB
113 lines

Config Loader

A Rust library for loading configuration files (JSON, TOML, YAML) into Rust structs with environment variable overrides and validation.

Features

  • Load configuration from JSON, TOML, or YAML files.
  • Override configuration values with environment variables.
  • Validate configuration using custom rules.

Usage

Add the crate to your Cargo.toml:

[dependencies]
config_loader = "0.2"

use config_loader::{load_config, validate_config, Validatable};
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize)]
struct Config {
    database: DatabaseConfig,
    server: ServerConfig,
}

fn main() {
    let config: Config = load_config("config.json").unwrap();
    validate_config(&config).unwrap();
    println!("{:?}", config);
}

Dependencies

~2.3–3.5MB
~71K SLoC