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:
- A
load()method that reads configuration from files and environment variables - A thread-safe static instance using
once_cell::Lazy - A getter function
get_{struct_name}()that returns anArc<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):
- Configuration file (JSON, TOML, YAML, etc.)
- 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.