3 unstable releases
0.2.0 | Aug 31, 2023 |
---|---|
0.1.1 | Aug 24, 2023 |
0.1.0 | Aug 24, 2023 |
#9 in #inner
29KB
476 lines
yaml_extras
Misc yaml-related utility functions.
Restructure
If you use YAML for a configuration file, you might want to allow to use both things like:
compiler:
command: cargo build
and:
compiler.command: cargo build
(Or not. I know I needed that. Whatever.)
The functions restructure_map
and restructure_from_str
allow just that,
converting dotted keys to inner fiels:
let s1 = r#"
compiler:
command: cargo build
"#;
let s2 = r#"
compiler.command: cargo build
"#;
let v1: serde_yaml::Value = serde_yaml::from_str(s1).unwrap();
let v2 = yaml_extras::restructure_from_str(&s2, true).unwrap();
assert_eq!(v1, v2);
License: MPL-2.0
lib.rs
:
Misc yaml-related utility functions.
Restructure
If you use YAML for a configuration file, you might want to allow to use both things like:
compiler:
command: cargo build
and:
compiler.command: cargo build
(Or not. I know I needed that. Whatever.)
The Restructurer
methods allow just that,
converting dotted keys to inner fiels:
let s1 = r#"
compiler:
command: cargo build
"#;
let s2 = r#"
compiler.command: cargo build
"#;
let v1: serde_yaml::Value = serde_yaml::from_str(s1)?;
let v2 = yaml_extras::Restructurer::new()
.apply_str(&s2)?;
assert_eq!(v1, v2);
Dependencies
~1.9–2.6MB
~56K SLoC