mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-10-14 21:20:48 +08:00
refactor(rust): adopt stable APIs through Rust 1.99 (#8193)
This commit is contained in:
@@ -8,7 +8,7 @@ repository = "https://github.com/clash-verge-rev/clash-verge-rev.git"
|
||||
default-run = "clash-verge"
|
||||
build = "build.rs"
|
||||
edition = "2024"
|
||||
rust-version = "1.95"
|
||||
rust-version = "1.99"
|
||||
|
||||
[lib]
|
||||
name = "app_lib"
|
||||
|
||||
@@ -271,10 +271,7 @@ fn proxy_bind_addresses(config: &Mapping) -> Result<Vec<IpAddr>> {
|
||||
return Ok(vec![IpAddr::V4(Ipv4Addr::LOCALHOST)]);
|
||||
}
|
||||
|
||||
let normalized = bind_address
|
||||
.strip_prefix('[')
|
||||
.and_then(|address| address.strip_suffix(']'))
|
||||
.unwrap_or(bind_address);
|
||||
let normalized = bind_address.strip_circumfix('[', ']').unwrap_or(bind_address);
|
||||
Ok(vec![
|
||||
IpAddr::from_str(normalized).with_context(|| format!("invalid bind-address {bind_address:?}"))?,
|
||||
])
|
||||
@@ -298,11 +295,7 @@ fn parse_listener_address(address: &str) -> Result<(Vec<IpAddr>, u16)> {
|
||||
if port == 0 {
|
||||
bail!("listener port must be between 1 and 65535");
|
||||
}
|
||||
let host = host
|
||||
.trim()
|
||||
.strip_prefix('[')
|
||||
.and_then(|host| host.strip_suffix(']'))
|
||||
.unwrap_or_else(|| host.trim());
|
||||
let host = host.trim().strip_circumfix('[', ']').unwrap_or_else(|| host.trim());
|
||||
if host.eq_ignore_ascii_case("localhost") {
|
||||
return Ok((vec![IpAddr::V4(Ipv4Addr::LOCALHOST)], port));
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ impl CoreManager {
|
||||
match event {
|
||||
tauri_plugin_shell::process::CommandEvent::Stdout(line)
|
||||
| tauri_plugin_shell::process::CommandEvent::Stderr(line) => {
|
||||
let message = String::from_utf8_lossy(&line).into_owned();
|
||||
let message = String::from_utf8_lossy_owned(line);
|
||||
Logger::global().writer_sidecar_log(Level::Error, &message);
|
||||
CLASH_LOGGER.append_log(message);
|
||||
}
|
||||
|
||||
@@ -1030,7 +1030,7 @@ pub(crate) async fn get_clash_log_snapshot_by_service() -> Result<String> {
|
||||
}
|
||||
let encoded = response.data.context("服务未返回核心日志快照")?;
|
||||
let content = decode_hex(&encoded).context("服务返回了无效的核心日志快照")?;
|
||||
Ok(String::from_utf8_lossy(&content).into_owned())
|
||||
Ok(String::from_utf8_lossy_owned(content))
|
||||
}
|
||||
|
||||
fn decode_hex(encoded: &str) -> Result<Vec<u8>> {
|
||||
|
||||
@@ -926,9 +926,7 @@ fn on_menu_event(_: &AppHandle, event: MenuEvent) {
|
||||
AsyncHandler::spawn(|| async move {
|
||||
match event.id.as_ref() {
|
||||
mode @ (MenuIds::RULE_MODE | MenuIds::GLOBAL_MODE | MenuIds::DIRECT_MODE) => {
|
||||
if let Some(stripped) = mode.strip_prefix("tray_")
|
||||
&& let Some(final_mode) = stripped.strip_suffix("_mode")
|
||||
{
|
||||
if let Some(final_mode) = mode.strip_circumfix("tray_", "_mode") {
|
||||
logging!(info, Type::ProxyMode, "Switch Proxy Mode To: {}", final_mode);
|
||||
let _ = feat::change_clash_mode(final_mode.into()).await;
|
||||
}
|
||||
|
||||
@@ -507,10 +507,7 @@ fn enforce_tun(mut config: Mapping, snapshot: Mapping) -> Mapping {
|
||||
|
||||
fn is_loopback_bind_address(addr: &str) -> bool {
|
||||
let addr = addr.trim();
|
||||
let addr = addr
|
||||
.strip_prefix('[')
|
||||
.and_then(|addr| addr.strip_suffix(']'))
|
||||
.unwrap_or(addr);
|
||||
let addr = addr.strip_circumfix('[', ']').unwrap_or(addr);
|
||||
|
||||
addr.eq_ignore_ascii_case("localhost")
|
||||
|| addr.parse::<std::net::IpAddr>().is_ok_and(|addr| addr.is_loopback())
|
||||
|
||||
@@ -412,14 +412,14 @@ mod tests {
|
||||
let system_exe = executable(&system.join("Tools/Clash Verge.app"))?;
|
||||
let user_exe = executable(&user.join("Network/Clash Verge.app"))?;
|
||||
|
||||
assert!(matches!(
|
||||
std::assert_matches!(
|
||||
evaluate_install_location_with_roots(&system_exe, &home, &system),
|
||||
LaunchLocation::Allowed { .. }
|
||||
));
|
||||
assert!(matches!(
|
||||
);
|
||||
std::assert_matches!(
|
||||
evaluate_install_location_with_roots(&user_exe, &home, &system),
|
||||
LaunchLocation::Allowed { .. }
|
||||
));
|
||||
);
|
||||
std::fs::remove_dir_all(root)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user