| Crates.io | nurv_config |
| lib.rs | nurv_config |
| version | 1.0.0 |
| created_at | 2026-01-18 18:18:02.379945+00 |
| updated_at | 2026-01-18 18:18:02.379945+00 |
| description | A Rust library for managing YAML configuration files in a structured way. |
| homepage | |
| repository | https://github.com/bugyboo/nurv_config |
| max_upload_size | |
| id | 2052795 |
| size | 11,648 |
A Rust wrpper library for config-rs to manage YAML configuration files in a structured way. It provides a simple API to load and merge configuration from multiple YAML files based on environment variables.
local.yaml, production.yaml)Add this to your Cargo.toml:
[dependencies]
nurv_config = { git = "https://github.com/bugyboo/nurv_config.git" }
serde = { version = "1.0", features = ["derive"] }
config/ directory in your project root.base.yaml file with your default configuration.local.yaml, production.yaml, etc.Example config/base.yaml:
app:
name: "My App"
port: 8080
Example config/local.yaml:
app:
port: 3000
database:
url: "localhost:5432"
The load_config! macro provides a convenient way to load configuration. It panics on failure, so use it when you're confident the config will load.
use nurv_config::load_config;
use serde::Deserialize;
#[derive(Deserialize)]
struct Config {
app: AppConfig,
database: DatabaseConfig,
}
#[derive(Deserialize)]
struct AppConfig {
name: String,
port: u16,
}
#[derive(Deserialize)]
struct DatabaseConfig {
url: String,
}
fn main() {
// Load config, inferring the type
let config: Config = load_config!();
// Or specify the type explicitly
let config = load_config!(Config);
// Or use the function
let config: Config = get_configuration()?;
println!("App name: {}", config.app.name);
println!("Port: {}", config.app.port);
println!("Database URL: {}", config.database.url);
}
Set the APP_ENV environment variable to load additional config files:
# Loads base.yaml + local.yaml
APP_ENV=local cargo run
# Loads base.yaml + production.yaml
APP_ENV=production cargo run
# Loads only base.yaml
cargo run
load_config!() - Load configuration, panicking on error. Type inferred.load_config!(Type) - Load configuration of specified type, panicking on error.get_configuration<T>() -> Result<T, ConfigError> - Load configuration with error handling.ConfigError - Enum representing possible configuration errors (IO or Config parsing).Run the tests with:
cargo test
The tests use the example config files in config/.
This project is licensed under MIT OR Apache-2.0.