Crates.io | Hconfig |
lib.rs | Hconfig |
version | 2.0.0 |
created_at | 2024-07-24 19:51:36.528972+00 |
updated_at | 2025-08-15 16:14:40.716129+00 |
description | Json configuration file manager |
homepage | |
repository | https://github.com/hyultis/rust_Hconfig |
max_upload_size | |
id | 1314282 |
size | 39,427 |
A file configuration manager library that simplifies access to JSON (and other formats) configuration files from a directory.
The key feature of this library is that any variable can be accessed using a path.
Saving is performed atomically, preventing partial reads from other applications/processes/etc. (saving to a temporary file before renaming).
The tinyjson
crate is re-exported via HConfig::tinyjson
.
fn main() {
// Configuration path: the directory must exist or be created before proceeding
HConfigManager::singleton().setConfPath("./config");
// Initialize a new configuration "example" with WrapperJson; it will be stored as "./config/example.json"
HConfigManager::singleton().create::<WrapperJson>("example").expect("Cannot create HConfig");
// Retrieve a configuration: the name "example" corresponds to "./config/example.json"
let mut config = HConfigManager::singleton().get("example").expect("Cannot get HConfig");
// Example of retrieving a variable and parsing it as a string (parsing is done via tinyjson)
let my_var: Option<JsonValue> = config.value_get("testget");
let my_string: String = config.value_get("testget").unwrap().try_into().unwrap();
// Set "path/to/save" to "test is updated"
config.value_set("path/to/save", "test is updated".to_string());
// Save configuration changes
config.save();
}
You can also check the tests.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.