* feat: update Cargo.toml for 2024 edition and optimize release profiles * feat: refactor environment variable settings for Linux and improve code organization * Refactor conditional statements to use `&&` for improved readability - Updated multiple files to combine nested `if let` statements using `&&` for better clarity and conciseness. - This change enhances the readability of the code by reducing indentation levels and making the conditions more straightforward. - Affected files include: media_unlock_checker.rs, profile.rs, clash.rs, profiles.rs, async_proxy_query.rs, core.rs, handle.rs, hotkey.rs, service.rs, timer.rs, tray/mod.rs, merge.rs, seq.rs, config.rs, proxy.rs, window.rs, general.rs, dirs.rs, i18n.rs, init.rs, network.rs, and window.rs in the resolve module. * refactor: streamline conditional checks using `&&` for improved readability * fix: update release profile settings for panic behavior and optimization * fix: adjust optimization level in Cargo.toml and reorder imports in lightweight.rs
62 lines
1.3 KiB
Rust
62 lines
1.3 KiB
Rust
use super::use_lowercase;
|
|
use serde_yaml_ng::{self, Mapping, Value};
|
|
|
|
fn deep_merge(a: &mut Value, b: &Value) {
|
|
match (a, b) {
|
|
(&mut Value::Mapping(ref mut a), Value::Mapping(b)) => {
|
|
for (k, v) in b {
|
|
deep_merge(a.entry(k.clone()).or_insert(Value::Null), v);
|
|
}
|
|
}
|
|
(a, b) => *a = b.clone(),
|
|
}
|
|
}
|
|
|
|
pub fn use_merge(merge: Mapping, config: Mapping) -> Mapping {
|
|
let mut config = Value::from(config);
|
|
let merge = use_lowercase(merge.clone());
|
|
|
|
deep_merge(&mut config, &Value::from(merge));
|
|
|
|
config.as_mapping().cloned().unwrap_or_else(|| {
|
|
log::error!("Failed to convert merged config to mapping, using empty mapping");
|
|
Mapping::new()
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn test_merge() -> anyhow::Result<()> {
|
|
let merge = r"
|
|
prepend-rules:
|
|
- prepend
|
|
- 1123123
|
|
append-rules:
|
|
- append
|
|
prepend-proxies:
|
|
- 9999
|
|
append-proxies:
|
|
- 1111
|
|
rules:
|
|
- replace
|
|
proxy-groups:
|
|
- 123781923810
|
|
tun:
|
|
enable: true
|
|
dns:
|
|
enable: true
|
|
";
|
|
|
|
let config = r"
|
|
rules:
|
|
- aaaaa
|
|
script1: test
|
|
";
|
|
|
|
let merge = serde_yaml_ng::from_str::<Mapping>(merge)?;
|
|
let config = serde_yaml_ng::from_str::<Mapping>(config)?;
|
|
|
|
let _ = serde_yaml_ng::to_string(&use_merge(merge, config))?;
|
|
|
|
Ok(())
|
|
}
|