mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 17:13:45 +08:00
31 lines
874 B
Rust
31 lines
874 B
Rust
use serde_yaml::{Mapping, Value};
|
|
|
|
macro_rules! revise {
|
|
($map: expr, $key: expr, $val: expr) => {
|
|
let ret_key = Value::String($key.into());
|
|
$map.insert(ret_key, Value::from($val));
|
|
};
|
|
}
|
|
|
|
// if key not exists then append value
|
|
#[allow(unused_macros)]
|
|
macro_rules! append {
|
|
($map: expr, $key: expr, $val: expr) => {
|
|
let ret_key = Value::String($key.into());
|
|
if !$map.contains_key(&ret_key) {
|
|
$map.insert(ret_key, Value::from($val));
|
|
}
|
|
};
|
|
}
|
|
|
|
pub async fn use_tun(mut config: Mapping, enable: bool) -> Mapping {
|
|
let tun_key = Value::from("tun");
|
|
let tun_val = config.get(&tun_key);
|
|
let mut tun_val = tun_val.map_or(Mapping::new(), |val| {
|
|
val.as_mapping().cloned().unwrap_or(Mapping::new())
|
|
});
|
|
revise!(tun_val, "enable", enable);
|
|
revise!(config, "tun", tun_val);
|
|
config
|
|
}
|