Expand description
§confmap
A library for reading config file into a map in memory. This library is based on serde_json and once_cell. after the config file is read, you can easily get the config by using get_string, get_int64, get_bool… This library is created because I cannot find a library like this in rust. (the idea is the same to viper package in golang)
example: put a json format file in your project folder like this:
config.json
{
"testGetString": "YesMan",
"testGetInt64": 43,
"testGetStringArray": [
"+44 1234567",
"+44 2345678"
]
}
add dependency in Cargo.toml:
[dependencies]
confmap = "1.0.0"
in your project main.rs:
use confmap;
fn main() {
confmap::add_config_path(path_str);
confmap::set_config_name("config.json");
confmap::read_config();
assert_eq!(Some("YesMan".to_string()), confmap::get_string("testGetString"));
assert_eq!(Some(43), confmap::get_int64("testGetInt64"));
assert_eq!(Some(vec!["+44 1234567".to_string(), "+44 2345678".to_string()]), confmap::get_string_array("testGetStringArray"));
}
Functions§
- add_
config_ path - Add path of the file. this will allow you to put config file in other path
- get
- this function will return Option<serde_json::Value> when you put a key argument.
- get_
array - this function will return Option<Vec<serde_json::Value>> when you put a key argument.
- get_
bool - this function will return Option
when you put a key argument. - get_
float32 - this function will return Option
when you put a key argument. - get_
float64 - this function will return Option
when you put a key argument. - get_
float64_ array - this function will return Option<Vec
> when you put a key argument. - get_i16
- this function will return Option
when you put a key argument. - get_i32
- this function will return Option
when you put a key argument. - get_
int8 - this function will return Option
when you put a key argument. - get_
int64 - this function will return Option
when you put a key argument. - get_
int64_ array - this function will return Option<Vec
> when you put a key argument. - get_map
- this function will return Option<Map<String, Value>> when you put a key argument.
- get_
string - this function will return Option
when you put a key argument. - get_
string_ array - this function will return Option<Vec
> when you put a key argument. - read_
config - this function read config file after file path and file name are given. you can use get_string, get_int64 …etc, to get the value after config file is loaded by this function.
- set_
config_ name - Set filename. put config file in the folder of the executable file