mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-06 06:30:03 +08:00
chore(rust): upgrade to 1.100 and consolidate Clippy rules (#8636)
This commit is contained in:
@@ -279,8 +279,7 @@ async fn cleanup_auto_backups() -> Result<()> {
|
||||
.and_then(|meta| meta.modified())
|
||||
.ok()
|
||||
.and_then(|time| time.duration_since(UNIX_EPOCH).ok())
|
||||
.map(|dur| dur.as_secs())
|
||||
.unwrap_or(0);
|
||||
.map_or(0, |dur| dur.as_secs());
|
||||
|
||||
files.push((path, modified));
|
||||
}
|
||||
|
||||
@@ -539,18 +539,16 @@ fn bind_socket(claim: &BindClaim) -> io::Result<Socket> {
|
||||
}
|
||||
|
||||
fn is_bind_conflict(error: &io::Error) -> bool {
|
||||
if error.kind() == io::ErrorKind::AddrInUse {
|
||||
return true;
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
{
|
||||
use windows_sys::Win32::Networking::WinSock::WSAEACCES;
|
||||
|
||||
error.raw_os_error() == Some(WSAEACCES)
|
||||
error.kind() == io::ErrorKind::AddrInUse || error.raw_os_error() == Some(WSAEACCES)
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
false
|
||||
{
|
||||
error.kind() == io::ErrorKind::AddrInUse
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
|
||||
@@ -14,10 +14,10 @@ use anyhow::{Result, anyhow};
|
||||
use clash_verge_draft::DraftTransaction;
|
||||
use clash_verge_logging::{Type, logging};
|
||||
use clash_verge_service_ipc::StageRuntimeOutcome;
|
||||
use scopeguard::defer;
|
||||
use smartstring::alias::String;
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
mem::DropGuard,
|
||||
path::PathBuf,
|
||||
sync::Arc,
|
||||
time::{Duration, Instant},
|
||||
@@ -191,9 +191,9 @@ impl CoreManager {
|
||||
logging!(debug, Type::Core, "Configuration update is already running");
|
||||
return Ok(ValidationOutcome::Busy);
|
||||
}
|
||||
defer! {
|
||||
let _config_update = DropGuard::new((), |()| {
|
||||
self.finish_config_update();
|
||||
}
|
||||
});
|
||||
|
||||
if !force && !self.should_update_config() {
|
||||
logging!(debug, Type::Core, "Skipping config update due to debounce");
|
||||
@@ -314,9 +314,9 @@ impl CoreManager {
|
||||
logging!(debug, Type::Core, "Configuration update is already running");
|
||||
return Ok(ValidationOutcome::Busy);
|
||||
}
|
||||
defer! {
|
||||
let _config_update = DropGuard::new((), |()| {
|
||||
self.finish_config_update();
|
||||
}
|
||||
});
|
||||
|
||||
let runtime = Config::runtime().await;
|
||||
let transaction = DraftTransaction::begin(vec![&runtime])?;
|
||||
|
||||
@@ -6,9 +6,8 @@ use crate::core::proxy_control::{self, SysproxyFailure};
|
||||
use crate::core::service::{SERVICE_MANAGER, ServiceStatus};
|
||||
use anyhow::Result;
|
||||
use clash_verge_logging::{Type, logging};
|
||||
use scopeguard::defer;
|
||||
use smartstring::alias::String;
|
||||
use std::path::Path;
|
||||
use std::{mem::DropGuard, path::Path};
|
||||
#[cfg(target_os = "windows")]
|
||||
use tauri_plugin_clash_verge_sysinfo::is_current_app_handle_admin;
|
||||
|
||||
@@ -356,9 +355,9 @@ impl CoreManager {
|
||||
if !self.try_start_config_update() {
|
||||
anyhow::bail!("configuration update is already running");
|
||||
}
|
||||
defer! {
|
||||
let _config_update = DropGuard::new((), |()| {
|
||||
self.finish_config_update();
|
||||
}
|
||||
});
|
||||
self.start_core_during_config_update().await
|
||||
}
|
||||
|
||||
@@ -383,9 +382,9 @@ impl CoreManager {
|
||||
service_rejection,
|
||||
));
|
||||
}
|
||||
defer! {
|
||||
let _config_update = DropGuard::new((), |()| {
|
||||
self.finish_config_update();
|
||||
}
|
||||
});
|
||||
// Lock order is config then lifecycle. disable_tun_and_persist commits the shared Verge
|
||||
// draft without claiming it, so without this it can commit another transaction's staged patch.
|
||||
let config_write = Config::lock_config_write().await;
|
||||
@@ -463,9 +462,9 @@ impl CoreManager {
|
||||
if !self.try_start_config_update() {
|
||||
anyhow::bail!("configuration update is already running");
|
||||
}
|
||||
defer! {
|
||||
let _config_update = DropGuard::new((), |()| {
|
||||
self.finish_config_update();
|
||||
}
|
||||
});
|
||||
// Lock order is config then lifecycle, for the unclaimed draft write below.
|
||||
let _config_write = Config::lock_config_write().await;
|
||||
let _life = self.lifecycle_lock.lock().await;
|
||||
@@ -795,9 +794,9 @@ impl CoreManager {
|
||||
if !self.try_start_config_update() {
|
||||
anyhow::bail!("configuration update is already running");
|
||||
}
|
||||
defer! {
|
||||
let _config_update = DropGuard::new((), |()| {
|
||||
self.finish_config_update();
|
||||
}
|
||||
});
|
||||
self.restart_core_during_config_update().await
|
||||
}
|
||||
|
||||
@@ -966,9 +965,9 @@ impl CoreManager {
|
||||
if !self.try_start_config_update() {
|
||||
return HandoffOutcome::NotReady;
|
||||
}
|
||||
defer! {
|
||||
let _config_update = DropGuard::new((), |()| {
|
||||
self.finish_config_update();
|
||||
}
|
||||
});
|
||||
|
||||
// Lock order is config then lifecycle.
|
||||
let _life = self.lifecycle_lock.lock().await;
|
||||
|
||||
@@ -331,9 +331,7 @@ fn build_provider_records(
|
||||
providers: Option<ProxyProviders>,
|
||||
records: &mut BTreeMap<String, ProxyNodeView>,
|
||||
) -> (Vec<ProxyProviderView>, ProviderCandidates) {
|
||||
let providers = providers
|
||||
.map(|providers| providers.providers.into_iter().collect::<BTreeMap<_, _>>())
|
||||
.unwrap_or_default();
|
||||
let providers = providers.map_or_default(|providers| providers.providers.into_iter().collect::<BTreeMap<_, _>>());
|
||||
let mut views = Vec::new();
|
||||
let mut candidates = BTreeMap::new();
|
||||
|
||||
|
||||
@@ -126,8 +126,7 @@ fn allocate_provider_destination(destination: &str, url: &str, reserved: &mut Ha
|
||||
let path = Path::new(destination);
|
||||
let extension = path
|
||||
.extension()
|
||||
.map(|ext| format!(".{}", ext.to_string_lossy()))
|
||||
.unwrap_or_default();
|
||||
.map_or_default(|ext| format!(".{}", ext.to_string_lossy()));
|
||||
let mut suffix = String::new();
|
||||
let mut sequence = 0;
|
||||
loop {
|
||||
|
||||
@@ -1470,10 +1470,7 @@ async fn create_sync_temp(target: &Path) -> Result<(PathBuf, tokio::fs::File)> {
|
||||
.await
|
||||
.with_context(|| format!("failed to create provider cache directory {}", parent.display()))?;
|
||||
}
|
||||
let name = target
|
||||
.file_name()
|
||||
.map(|name| name.to_string_lossy())
|
||||
.unwrap_or_default();
|
||||
let name = target.file_name().map_or_default(|name| name.to_string_lossy());
|
||||
use crate::utils::retry::{RetryError, RetryPolicy, retry};
|
||||
retry(
|
||||
RetryPolicy::fixed(std::num::NonZeroUsize::MIN.saturating_add(7), std::time::Duration::ZERO),
|
||||
|
||||
@@ -7,9 +7,9 @@ use crate::{
|
||||
use anyhow::Result;
|
||||
use clash_verge_logging::{Type, logging};
|
||||
use parking_lot::RwLock;
|
||||
use scopeguard::defer;
|
||||
use smartstring::alias::String;
|
||||
use std::{
|
||||
mem::DropGuard,
|
||||
sync::{
|
||||
Arc,
|
||||
atomic::{AtomicBool, Ordering},
|
||||
@@ -541,9 +541,9 @@ impl Sysopt {
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
defer! {
|
||||
let _reset_sysproxy = DropGuard::new((), |()| {
|
||||
self.reset_sysproxy.store(false, Ordering::SeqCst);
|
||||
}
|
||||
});
|
||||
let mut proxy_state = self.proxy_state_lock.lock().await;
|
||||
let _guard_operation = self.guard_operation_lock.lock().await;
|
||||
let drained = self.stop_proxy_guard_locked().await;
|
||||
|
||||
@@ -210,8 +210,7 @@ impl Tray {
|
||||
.latest_arc()
|
||||
.0
|
||||
.get("mode")
|
||||
.map(|val| val.as_str().unwrap_or("rule"))
|
||||
.unwrap_or("rule")
|
||||
.map_or("rule", |val| val.as_str().unwrap_or("rule"))
|
||||
.to_owned()
|
||||
};
|
||||
let profiles_config = Config::profiles().await;
|
||||
@@ -414,26 +413,23 @@ impl Tray {
|
||||
}
|
||||
|
||||
fn create_hotkeys(hotkeys: &Option<Vec<String>>) -> HashMap<&str, &str> {
|
||||
hotkeys
|
||||
.as_ref()
|
||||
.map(|h| {
|
||||
h.iter()
|
||||
.filter_map(|item| {
|
||||
let mut parts = item.split(',');
|
||||
match (parts.next(), parts.next()) {
|
||||
(Some(func), Some(key)) => {
|
||||
// 托盘菜单的 `accelerator` 在 Linux/Windows 下不支持小键盘按键,Windows 下也不支持 Win 键(前端上报为 `CMD`)
|
||||
let uppercase_key = key.to_uppercase();
|
||||
let unsupported =
|
||||
uppercase_key.contains("NUMPAD") || (cfg!(windows) && uppercase_key.contains("CMD"));
|
||||
if unsupported { None } else { Some((func, key)) }
|
||||
}
|
||||
_ => None,
|
||||
hotkeys.as_ref().map_or_default(|h| {
|
||||
h.iter()
|
||||
.filter_map(|item| {
|
||||
let mut parts = item.split(',');
|
||||
match (parts.next(), parts.next()) {
|
||||
(Some(func), Some(key)) => {
|
||||
// 托盘菜单的 `accelerator` 在 Linux/Windows 下不支持小键盘按键,Windows 下也不支持 Win 键(前端上报为 `CMD`)
|
||||
let uppercase_key = key.to_uppercase();
|
||||
let unsupported =
|
||||
uppercase_key.contains("NUMPAD") || (cfg!(windows) && uppercase_key.contains("CMD"));
|
||||
if unsupported { None } else { Some((func, key)) }
|
||||
}
|
||||
})
|
||||
.collect::<HashMap<&str, &str>>()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
.collect::<HashMap<&str, &str>>()
|
||||
})
|
||||
}
|
||||
|
||||
fn create_profile_menu_item(
|
||||
@@ -493,12 +489,14 @@ fn create_subcreate_proxy_menu_item(
|
||||
.proxies
|
||||
.get(proxy_str)
|
||||
.and_then(|h| h.history.last())
|
||||
.map(|h| match h.delay {
|
||||
0 => "-ms".into(),
|
||||
delay if delay >= 10000 => "-ms".into(),
|
||||
_ => format!("{}ms", h.delay),
|
||||
})
|
||||
.unwrap_or_else(|| "-ms".into());
|
||||
.map_or_else(
|
||||
|| "-ms".into(),
|
||||
|h| match h.delay {
|
||||
0 => "-ms".into(),
|
||||
delay if delay >= 10000 => "-ms".into(),
|
||||
_ => format!("{}ms", h.delay),
|
||||
},
|
||||
);
|
||||
|
||||
let display_text = format!("{} | {}", proxy_str, delay_text);
|
||||
|
||||
@@ -611,7 +609,7 @@ async fn create_tray_menu(
|
||||
config
|
||||
.get("proxy-groups")
|
||||
.and_then(|groups| groups.as_sequence())
|
||||
.map(|groups| {
|
||||
.map_or_default(|groups| {
|
||||
groups
|
||||
.iter()
|
||||
.filter_map(|group| group.get("name"))
|
||||
@@ -620,7 +618,6 @@ async fn create_tray_menu(
|
||||
.map(|(index, name)| (name.into(), index))
|
||||
.collect::<HashMap<String, usize>>()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
});
|
||||
|
||||
(proxy_nodes_data, runtime_proxy_groups_order)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use anyhow::Result;
|
||||
use scopeguard::defer;
|
||||
use serde::Serialize;
|
||||
use smartstring::alias::String;
|
||||
use std::{
|
||||
fmt,
|
||||
hash::{DefaultHasher, Hash as _, Hasher as _},
|
||||
mem::DropGuard,
|
||||
sync::LazyLock,
|
||||
sync::atomic::{AtomicBool, Ordering},
|
||||
};
|
||||
@@ -421,9 +421,9 @@ impl CoreConfigValidator {
|
||||
logging!(info, Type::Validate, "验证已在进行中,跳过新的验证请求");
|
||||
return Ok(ValidationOutcome::Busy);
|
||||
}
|
||||
defer! {
|
||||
let _validation = DropGuard::new((), |()| {
|
||||
self.finish();
|
||||
}
|
||||
});
|
||||
logging!(info, Type::Validate, "生成临时配置文件用于验证");
|
||||
|
||||
// The test run reads the app dir, which never sees updates made by a service core.
|
||||
@@ -449,8 +449,7 @@ fn has_ext<P: AsRef<std::path::Path>>(path: P, ext: &str) -> bool {
|
||||
path.as_ref()
|
||||
.extension()
|
||||
.and_then(|s| s.to_str())
|
||||
.map(|s| s.eq_ignore_ascii_case(ext))
|
||||
.unwrap_or(false)
|
||||
.is_some_and(|s| s.eq_ignore_ascii_case(ext))
|
||||
}
|
||||
|
||||
fn contains_any_keyword<'a>(buf: &'a [u8], keywords: &'a [&str]) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user