| Crates.io | iron_config_loader |
| lib.rs | iron_config_loader |
| version | 0.4.0 |
| created_at | 2025-12-16 15:41:16.019141+00 |
| updated_at | 2025-12-16 17:50:29.855844+00 |
| description | Unified configuration management for Iron Runtime |
| homepage | |
| repository | https://github.com/.../iron_runtime |
| max_upload_size | |
| id | 1988082 |
| size | 78,229 |
Unified configuration management for Iron Runtime with precedence-based resolution.
Configuration is resolved using the following precedence (highest to lowest):
Environment Variables - {MODULE}_KEY_NAME format (highest priority)
Project Config - {workspace}/config/{module}.{env}.toml
User Config - ~/.config/iron/{module}.toml
Workspace Defaults - {workspace}/config/{module}.default.toml
Crate Defaults - Hardcoded defaults in crate (lowest priority)
Precedence-based resolution: Clear, predictable configuration loading
Environment variable overrides: Override any config value via env vars
Multiple file layers: Project, user, and workspace-level configuration
Type-safe deserialization: Automatic conversion to Rust types via serde
Source tracking: Know which layer provided each configuration value
Workspace-relative paths: Context-independent configuration files
use iron_config_loader::ConfigLoader;
use serde::Deserialize;
#[derive(Deserialize)]
struct DatabaseConfig {
url: String,
max_connections: u32,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load configuration for module
let loader = ConfigLoader::new("iron_token_manager")?;
// Get individual values
let url: String = loader.get("database.url")?;
println!("Database URL: {}", url);
// Get configuration section as struct
let db_config: DatabaseConfig = loader.get_section("database")?;
println!("Max connections: {}", db_config.max_connections);
Ok(())
}
Environment variables follow the pattern {MODULE}_{KEY_PATH}:
# Override database.url for iron_token_manager
export IRON_TOKEN_MANAGER_DATABASE_URL="sqlite:///custom.db"
# Override database.max_connections
export IRON_TOKEN_MANAGER_DATABASE_MAX_CONNECTIONS="10"
# Override nested values: database.pool.timeout
export IRON_TOKEN_MANAGER_DATABASE_POOL_TIMEOUT="60"
Configuration files use TOML format:
Project Config ({workspace}/config/iron_token_manager.development.toml):
[database]
url = "sqlite:///{workspace}/iron.db?mode=rwc"
max_connections = 5
auto_migrate = true
[development]
debug = true
auto_seed = false
User Config (~/.config/iron/iron_token_manager.toml):
[development]
debug = true # Personal preference
Load with specific environment:
let loader = ConfigLoader::with_env("iron_token_manager", "production")?;
Provide default values:
let defaults = r#"
[database]
url = "sqlite:///:memory:"
max_connections = 5
"#;
let loader = ConfigLoader::with_defaults("iron_token_manager", defaults)?;
Get value with source information:
let (url, source) = loader.get_with_source::<String>("database.url")?;
println!("Database URL: {} (from {})", url, source);
// Output: Database URL: sqlite:///iron.db (from env:IRON_TOKEN_MANAGER_DATABASE_URL)
Debug configuration:
println!("{}", loader.debug_summary());
Cargo.toml:
[dependencies]
iron_config_loader = { workspace = true }
serde = { workspace = true, features = ["derive"] }
Before (custom config loading):
// Old: 252 lines of HashMap-based config hierarchy
let config = load_config_from_multiple_sources()?;
After (iron_config_loader):
// New: Single line with full precedence system
let loader = ConfigLoader::new("my_module")?;
let config: MyConfig = loader.get_section("my_section")?;
This crate is part of Phase 2 (Configuration Unification) of the workspace_tools adoption plan:
iron_config_loader/
├── src/
│ ├── lib.rs # Public API
│ ├── error.rs # Error types
│ ├── layer.rs # Configuration layer implementations
│ └── loader.rs # ConfigLoader implementation
├── tests/
│ ├── precedence_test.rs # Precedence system tests
│ ├── env_layer_test.rs # Environment variable layer tests
│ └── file_layer_test.rs # File layer tests
├── Cargo.toml
└── readme.md
Run tests:
cargo test --all-features
Run tests with clippy:
cargo clippy --all-targets --all-features -- -D warnings
MIT