Dyson Boot
A convenient Rust crate for quickly bootstrapping application configuration with minimal boilerplate.
Features
- 🚀 Zero-boilerplate configuration loading - Generate configuration loaders with a simple macro
- 🔄 Multi-source configuration - Automatically loads from config files and environment variables
- 🔒 Thread-safe singleton pattern - Lazily-initialized, globally accessible configuration
- 📝 Type-safe - Leverages Rust's type system with
serdefor deserialization - 🌍 Environment variable override - Override any config value via environment variables
Installation
Add this to your Cargo.toml:
[]
= "0.1"
= "0.14"
= { = "1.0", = ["derive"] }
= "1.0"
Quick Start
Basic Usage
use settings_struct;
use ;
// Generate configuration loader with defaults
settings_struct!;
Create a config.json file:
Custom Configuration
You can customize the configuration source:
settings_struct!;
Environment Variable Override
Override any config value using environment variables with the specified prefix and separator:
# Override host and port
# Override nested config (if you have nested structs)
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 lifetime of the application.
Configuration Priority
Configuration values are loaded in the following order (later sources override earlier ones):
- Configuration file (JSON, TOML, YAML, etc.)
- Environment variables with the specified prefix
Examples
With Custom Environment Variables
use settings_struct;
use ;
settings_struct!;
Set environment variables:
Testing
The crate includes testing utilities. See the tests/ directory for examples:
use TempDir;
use ;
Requirements
- Rust 1.70 or later
- Your config struct must implement
DeserializeandSerializefromserde
License
Licensed under the same terms as the parent workspace.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.