mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-28 00:10:05 +08:00
* refactor(config): adopt tristr for config strings Wire the tristr git dependency (pinned rev) and switch the config and enhance modules from smartstring::alias::String to tristr::alias::String. Drop the smartstring-era per-field specta overrides except the three webdav fields required by serialize_with and the ipc::JsonValue bridge: tristr maps to Primitive::str natively and the generated bindings stay byte-identical (gen-contract --check passes). Call sites in not-yet-migrated modules (cmd/core/feat/utils) are bridged with explicit tristr::alias::String paths and as_str().into() conversions; each bridge is absorbed when its module migrates. * refactor(cmd): adopt tristr for command strings Switch the cmd module from smartstring::alias::String to tristr::alias::String and drop its smartstring-era per-field specta overrides (ProfileSelection/ProfileCreate/ProfilePatch, RuntimeLogs); bindings stay byte-identical. Calls into not-yet-migrated feat/core functions keep smartstring-typed locals via full paths until those modules migrate. * refactor(core): adopt tristr for core strings Switch the core module (validate, timer, sysopt, backup, hotkey, tray, manager, notify) from smartstring::alias::String to tristr::alias::String and drop the smartstring-era specta overrides on ValidationOutcome and the notify payload structs; bindings stay byte-identical. WebDAV calls from the not-yet-migrated feat module are bridged with as_str().into(). * refactor(feat): adopt tristr for feature strings Switch the feat module (backup, icon, dns, profile, clash) from smartstring::alias::String to tristr::alias::String, drop its smartstring-era specta overrides (IconInfo, backup listings, DnsOverrideOutcome), and absorb the temporary smartstring-typed bridge locals the cmd module used to call into feat. * refactor(utils): adopt tristr for utility strings Switch utils/network.rs and utils/resolve/scheme.rs from smartstring::alias::String to tristr::alias::String and absorb the temporary user_agent and profile-name bridge conversions. * refactor(deps): drop smartstring in favor of tristr Remove the smartstring workspace and member dependencies and its Cargo.lock entry; tristr is the only string representation left. * build(deps): bump tristr to fuzz-harness fix rev Pin 3738d8c renames the stale vstr path dependency in the upstream fuzz manifest so its seven targets build again; library code is unchanged from 3756ed1a.
76 lines
1.9 KiB
Rust
76 lines
1.9 KiB
Rust
use serde_yaml_ng::{Mapping, Value};
|
|
use tristr::alias::String;
|
|
|
|
pub const HANDLE_FIELDS: [&str; 12] = [
|
|
"mode",
|
|
"redir-port",
|
|
"tproxy-port",
|
|
"mixed-port",
|
|
"socks-port",
|
|
"port",
|
|
"allow-lan",
|
|
"log-level",
|
|
"ipv6",
|
|
"external-controller",
|
|
"secret",
|
|
"unified-delay",
|
|
];
|
|
|
|
pub const DEFAULT_FIELDS: [&str; 5] = ["proxies", "proxy-providers", "proxy-groups", "rule-providers", "rules"];
|
|
|
|
fn lowercase_key(key: &str) -> Value {
|
|
let mut key = String::from(key);
|
|
key.make_ascii_lowercase();
|
|
Value::from(key.as_str())
|
|
}
|
|
|
|
pub fn use_lowercase(config: Mapping) -> Mapping {
|
|
let mut lowercased = Mapping::new();
|
|
|
|
for (key, value) in config {
|
|
if let Some(key_str) = key.as_str() {
|
|
lowercased.insert(lowercase_key(key_str), value);
|
|
}
|
|
}
|
|
lowercased
|
|
}
|
|
|
|
pub fn use_sort(mut config: Mapping) -> Mapping {
|
|
let mut sorted = Mapping::new();
|
|
HANDLE_FIELDS.into_iter().for_each(|key| {
|
|
let key = Value::from(key);
|
|
if let Some(value) = config.remove(&key) {
|
|
sorted.insert(key, value);
|
|
}
|
|
});
|
|
|
|
let mut default_field_values = Mapping::new();
|
|
for (key, value) in config {
|
|
if let Some(key_str) = key.as_str() {
|
|
if DEFAULT_FIELDS.contains(&key_str) {
|
|
default_field_values.insert(key, value);
|
|
} else if !HANDLE_FIELDS.contains(&key_str) {
|
|
sorted.insert(key, value);
|
|
}
|
|
}
|
|
}
|
|
|
|
DEFAULT_FIELDS.into_iter().for_each(|key| {
|
|
let key = Value::from(key);
|
|
if let Some(value) = default_field_values.remove(&key) {
|
|
sorted.insert(key, value);
|
|
}
|
|
});
|
|
|
|
sorted
|
|
}
|
|
|
|
#[inline]
|
|
pub fn use_keys<'a>(config: &'a Mapping) -> impl Iterator<Item = String> + 'a {
|
|
config.iter().filter_map(|(key, _)| key.as_str()).map(|s: &str| {
|
|
let mut s: String = s.into();
|
|
s.make_ascii_lowercase();
|
|
s
|
|
})
|
|
}
|