3 stable releases

1.1.0 Aug 17, 2024
1.0.1 Aug 17, 2024
1.0.0 Jul 24, 2024

#292 in Configuration

Download history 123/week @ 2024-07-23 9/week @ 2024-07-30 217/week @ 2024-08-13 24/week @ 2024-08-20 21/week @ 2024-09-10 15/week @ 2024-09-17 9/week @ 2024-09-24 12/week @ 2024-10-01 1/week @ 2024-10-08

83 downloads per month
Used in htrace

MIT/Apache

13KB
318 lines

HConfig

A file configuration manager library that simplify access of json configuration files from a dir.

if a config file is not existing, it will be created. Any var is accessed by a path. Saving use atomic method disallowing partial load from other app/process/etc.

the used serde_json crate is re-exported via "Hconfig::serde_json"

Online Documentation

Master branch

Example

fn main()
{
    // configuration path, the directory need to be existing or created before continuing
	HConfigManager::singleton().setConfPath("./config");
	
	// get a "config", the name "example" mean "./config/example.json"
	let mut config = HConfigManager::singleton().get("example");
	
	// exemple of getting a var and getting a string (parse is from serde_json)
	let myVar: Option<Value> = config.get("name");
	let myString: String = config.get("path/to/myvar").unwrap().as_str().unwrap().to_string();
	
	config.set("path/to/save",JsonValue::String("test is update".to_string()));
	
	// save config modification.
	config.save();
}

you can also check 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.

Dependencies

~2–8MB
~59K SLoC