pub fn load_json<'a, T>(
app_name: impl AsRef<str>,
config_name: impl Into<Option<&'a str>>,
location: impl AsRef<ConfigLocation>,
reset_conf_on_err: bool,
) -> Result<T, ConfigError>Expand description
Loads a config file from the config, cache, cwd, or local data directory of the current user. In json format.
It will load a config file, deserialize it and return it.
If the flag reset_conf_on_err is set to true, the config file will be reset to the default config if
the deserialization fails, if set to false an error will be returned.
§Errors
This function will return an error if the config, cache or local data directory could not be found or created, or if something went wrong while deserializing the config.
If the flag reset_conf_on_err is set to false and the deserialization fails, an error will be returned. If it is set to true the config file will be reset to the default config.
§Example
use binconf::ConfigLocation::{Cache, Config, LocalData, Cwd};
use serde::{Deserialize, Serialize};
#[derive(Default, Serialize, Deserialize, PartialEq, Debug)]
struct TestConfig {
test: String,
test_vec: Vec<u8>,
}
let config = binconf::load_json::<TestConfig>("test-binconf-read-json", None, Config, false).unwrap();
assert_eq!(config, TestConfig::default());