refactor: IRuntime::patch_config()

This commit is contained in:
huzibaca 2024-10-23 10:34:14 +08:00
parent 2ab75db9c9
commit 30b0c45539
No known key found for this signature in database
GPG Key ID: D4364EE4851DC302

View File

@ -26,20 +26,24 @@ impl IRuntime {
config.insert(key.into(), value.clone()); config.insert(key.into(), value.clone());
} }
}); });
let tun = config.get("tun");
let mut tun = tun.map_or(Mapping::new(), |val| {
val.as_mapping().cloned().unwrap_or(Mapping::new())
});
let patch_tun = patch.get("tun"); let patch_tun = patch.get("tun");
let patch_tun = patch_tun.map_or(Mapping::new(), |val| { if patch_tun.is_some() {
val.as_mapping().cloned().unwrap_or(Mapping::new()) let tun = config.get("tun");
}); let mut tun = tun.map_or(Mapping::new(), |val| {
use_keys(&patch_tun).into_iter().for_each(|key| { val.as_mapping().cloned().unwrap_or(Mapping::new())
if let Some(value) = patch_tun.get(&key).to_owned() { });
tun.insert(key.into(), value.clone()); let patch_tun = patch_tun.map_or(Mapping::new(), |val| {
} val.as_mapping().cloned().unwrap_or(Mapping::new())
}); });
config.insert("tun".into(), Value::from(tun)); use_keys(&patch_tun).into_iter().for_each(|key| {
if let Some(value) = patch_tun.get(&key).to_owned() {
tun.insert(key.into(), value.clone());
}
});
config.insert("tun".into(), Value::from(tun));
}
} }
} }
} }