Module plugx_config::parser::yaml
source · Expand description
YAML configuration parser.
This is only usable if you enabled yaml Cargo feature.
Example
use plugx_config::parser::{ConfigurationParser, yaml::ConfigurationParserYaml};
use plugx_input::Input;
let bytes = br#"
hello:
- "w"
- "o"
- "l"
- "d"
foo:
bar:
baz: Qux
abc: 3.14
xyz: false
"#;
let parser = ConfigurationParserYaml::new();
// You can set nested key separator like this:
// parser.set_key_separator("__");
let parsed: Input = parser.try_parse(bytes.as_slice()).unwrap();
assert!(
parsed.map_ref().unwrap().len() == 2 &&
parsed.map_ref().unwrap().contains_key("foo") &&
parsed.map_ref().unwrap().contains_key("hello")
);
let foo = parsed.map_ref().unwrap().get("foo").unwrap();
assert!(
foo.map_ref().unwrap().len() == 2 &&
foo.map_ref().unwrap().contains_key("bar") &&
foo.map_ref().unwrap().contains_key("xyz")
);
let bar = foo.map_ref().unwrap().get("bar").unwrap();
assert_eq!(bar.map_ref().unwrap().get("baz").unwrap(), &"Qux".into());
assert_eq!(bar.map_ref().unwrap().get("abc").unwrap(), &3.14.into());
let xyz = foo.map_ref().unwrap().get("xyz").unwrap();
assert_eq!(xyz, &false.into());
let list = ["w", "o", "l", "d"].into();
assert_eq!(parsed.map_ref().unwrap().get("hello").unwrap(), &list);