A configuration parsing library that provide macros and convenience functions for generating configuration schema, sanity check, flush, refresh, etc. Design for .toml
and .ini
.
use ov_config::*;
makeconfig!(
TestConfig,
SECTION1 {
//key: Type: Default Value => Verification closure
astring: String: "key1".into() => |x: &String| x.len() > 0,
avector: Vec
fn main() { let config = TestConfig{..Default::default()}; asserteq!(config.SECTION1.astring, "key1"); asserteq!(config.SECTION1.avector, vec![1, 2, 3]); asserteq!(config.SECTION2.ai32, 15); asserteq!(config.SECTION2.abool, true); } ```
use ov_config::; use std::fs::File; use std::io::prelude::;
makeconfig!(
TestConfig,
SECTION1 {
//key: Type: Default Value => Verification closure
astring: String: "key1".into() => |x: &String| x.len() > 0,
avector: Vec
fn main() { let config = r#" [SECTION1] astring: iamastring avector: [1, 2, 3] [SECTION2] ai32: 12 a_bool: true "#;
let mut file = File::create("PATH_TO_CONFIG.ini").unwrap();
file.write_all(config.as_bytes()).unwrap();
file.sync_all().unwrap();
let config = TestConfig::get_config("PATH_TO_CONFIG.ini").unwrap();
assert_eq!(config.SECTION1.a_string, "i_am_a_string");
assert_eq!(config.SECTION1.a_vector, [1, 2, 3]);
assert_eq!(config.SECTION2.a_i32, 12);
assert_eq!(config.SECTION2.a_bool, true);
} ```
More details could be found from the documentation.