Hconfig

Crates.ioHconfig
lib.rsHconfig
version2.0.0
created_at2024-07-24 19:51:36.528972+00
updated_at2025-08-15 16:14:40.716129+00
descriptionJson configuration file manager
homepage
repositoryhttps://github.com/hyultis/rust_Hconfig
max_upload_size
id1314282
size39,427
(hyultis)

documentation

README

HConfig

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.

Online Documentation

Master branch

Example

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.

License

Licensed under either of

at your option.

Contribution

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.

Commit count: 32

cargo fmt