pilota_build/codegen/
toml.rs1pub fn merge_tomls(a: &mut toml::Value, b: toml::Value) {
2 match (a, b) {
3 (toml::Value::Boolean(a), toml::Value::Boolean(b)) => {
4 *a = b;
5 }
6 (toml::Value::String(a), toml::Value::String(b)) => *a = b,
7 (toml::Value::Array(a), toml::Value::Array(b)) => {
8 a.extend(b);
9 a.sort_by_key(|a| a.to_string());
10 a.dedup_by(|a, b| a.to_string() == b.to_string());
11 }
12 (toml::Value::Table(a), toml::Value::Table(b)) => b.into_iter().for_each(|(k, v)| {
13 if a.contains_key(&k) {
14 merge_tomls(a.get_mut(&k).unwrap(), v);
15 } else {
16 a.insert(k, v);
17 }
18 }),
19 (toml::Value::Table(_), toml::Value::String(_)) => {}
21 pair => panic!("can not merge {pair:?}"),
22 }
23}