| Crates.io | config-ro |
| lib.rs | config-ro |
| version | 0.1.0 |
| created_at | 2025-05-21 11:18:12.439845+00 |
| updated_at | 2025-05-21 11:18:12.439845+00 |
| description | A thread-safe configuration manager for Rust applications that loads and caches JSON configuration files. |
| homepage | |
| repository | https://github.com/kak-smko/config-ro |
| max_upload_size | |
| id | 1683301 |
| size | 30,147 |
A thread-safe configuration manager for Rust applications that loads and caches JSON configuration files.
RwLock synchronizationconfigs/ directory (e.g., configs/app.json):{
"db_host": "localhost",
"db_port": 5432,
"debug_mode": true
}
use config_ro::Config;
let config = Config::new("app");
let db_host: String = config.get("db_host").unwrap();
let db_port: u16 = config.get("db_port").unwrap();
let debug_mode: bool = config.get("debug_mode").unwrap();
// Create multiple configuration instances
let app_config = Config::new("app");
let db_config = Config::new("database");
// Get nested values (if your JSON has nested objects)
let nested_value = app_config.get::<String>("nested.key").unwrap();
// Handle missing values
match app_config.get::<String>("optional_key") {
Some(value) => println!("Got value: {}", value),
None => println!("Using default value"),
}
Config::new(name: &str) -> ConfigCreates a new configuration instance for the given name. The configuration is loaded from configs/{name}.json if not already cached.
config.get<T: DeserializeOwned>(key: &str) -> Option<T>Retrieves a configuration value by key, attempting to deserialize it into type T.
The configuration manager is designed for concurrent access:
Configuration loading is synchronized
Multiple threads can read configurations simultaneously
Configuration updates are exclusive (blocking other accesses during write)
{
"app_name": "My Application",
"version": "1.0.0",
"database": {
"host": "db.example.com",
"port": 5432,
"credentials": {
"username": "admin",
"password": "secret"
}
},
"features": {
"experimental": true,
"logging": "verbose"
}
}
Contributions are welcome! Please open an issue or submit a PR for:
New features
Performance improvements
Bug fixes
Dual-licensed under MIT or Apache 2.0 at your option.