Crate dyson_boot

Crate dyson_boot 

Source
Expand description

§Dyson Boot

A convenient Rust crate for quickly bootstrapping application configuration with minimal boilerplate.

§Features

  • Zero-boilerplate configuration loading with a simple macro
  • Multi-source configuration (files + environment variables)
  • Thread-safe singleton pattern with lazy initialization
  • Type-safe deserialization using serde
  • Environment variable override support

§Quick Example

use dyson_boot::settings_struct;
use serde::{Deserialize, Serialize};

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

// Generate configuration loader with defaults
settings_struct!(AppConfig);

fn main() {
    // Access configuration anywhere in your app
    let config = get_app_config();
    println!("Server running on {}:{}", config.host, config.port);
}

§How It Works

The settings_struct! macro generates:

  1. A load() method that reads configuration from files and environment variables
  2. A thread-safe static instance using once_cell::Lazy
  3. A getter function get_{struct_name}() that returns an Arc<YourConfig>

The configuration is loaded lazily on first access and cached for the application lifetime.

§Configuration Priority

Values are loaded in this order (later sources override earlier ones):

  1. Configuration file (JSON, TOML, YAML, etc.)
  2. Environment variables with the specified prefix

See the settings_struct macro documentation for more details.

Modules§

setting
Settings module

Macros§

settings_struct
Generates a configuration loader for a struct with file and environment variable support.