I am having trouble creating a recursive function to parse two serde_yaml::Value variables and combine them. It's easy enough to combine them at a base-level object, but then the sublevel values are only those of the combined value.
Given:
let original:serde_yaml::Value = serde_yaml::from_str(r#"
keyA:
subKeyA:
- A
- B
- C
keyB: "one"
keyC: "a"
"#
).unwrap();
let add_or_modify_these_values:serde_yaml::Value = serde_yaml::from_str(r#"
keyA:
subKeyA:
- D
subKeyB:
- BA
keyB: "two"
keyC:
- A
- B
"#
).unwrap();
How would I combine them so all nested properties are accounted for, eg:
keyA:
subKeyA:
- A
- B
- C
- D
subKeyB:
- BA
keyB: "two"
keyC:
- A
- B
When there are complications (for example, different value types like keyC) I'd prefer overwriting the original value type with the new one.
Edit: I've also looked at a similar question for json here: How can I merge two JSON objects with Rust? but that merge method will not combine array values, only overwrite.