From 3ce7070d84bd647d31e515d3d25f30e7f62056ff Mon Sep 17 00:00:00 2001 From: monosans Date: Thu, 28 May 2026 08:21:50 +0300 Subject: [PATCH] fix clippy errors --- src/checker.rs | 7 +++++-- src/http.rs | 7 +++++-- src/output.rs | 8 ++++++-- src/proxy.rs | 21 +++++++++++++-------- src/raw_config.rs | 28 ++++++++++++++++++---------- src/utils.rs | 2 +- 6 files changed, 48 insertions(+), 25 deletions(-) diff --git a/src/checker.rs b/src/checker.rs index 98655f5..036842f 100644 --- a/src/checker.rs +++ b/src/checker.rs @@ -6,14 +6,17 @@ use color_eyre::eyre::OptionExt as _; use crate::event::{AppEvent, Event}; use crate::{config::Config, proxy::Proxy, utils::pretty_error}; -pub async fn check_all( +pub async fn check_all( config: Arc, dns_resolver: R, proxies: Vec, mut tls_backend: rustls::ClientConfig, token: tokio_util::sync::CancellationToken, #[cfg(feature = "tui")] tx: tokio::sync::mpsc::UnboundedSender, -) -> crate::Result> { +) -> crate::Result> +where + R: reqwest::dns::Resolve + Clone + 'static, +{ if config.checking.check_url.is_none() { return Ok(proxies); } diff --git a/src/http.rs b/src/http.rs index 2d586d7..c59464c 100644 --- a/src/http.rs +++ b/src/http.rs @@ -181,11 +181,14 @@ impl reqwest_middleware::Middleware for RetryMiddleware { } } -pub fn create_reqwest_client( +pub fn create_reqwest_client( config: &Config, dns_resolver: R, mut tls_backend: rustls::ClientConfig, -) -> crate::Result { +) -> crate::Result +where + R: reqwest::dns::Resolve + 'static, +{ tls_backend.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()]; let mut builder = reqwest::ClientBuilder::new() .user_agent(config.scraping.user_agent.as_bytes()) diff --git a/src/output.rs b/src/output.rs index bf3702c..4335d07 100644 --- a/src/output.rs +++ b/src/output.rs @@ -61,10 +61,14 @@ fn strip_non_english_names(v: &mut serde_json::Value) { } #[expect(clippy::ref_option)] -fn serialize_opt_strip_names( +fn serialize_opt_strip_names( opt: &Option, serializer: S, -) -> Result { +) -> Result +where + T: serde::Serialize, + S: serde::Serializer, +{ if let Some(t) = opt { let mut v = serde_json::to_value(t).map_err(serde::ser::Error::custom)?; diff --git a/src/proxy.rs b/src/proxy.rs index 72a8e88..9797fbe 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -119,12 +119,15 @@ impl ProxySink for Vec { } impl Proxy { - pub async fn check( + pub async fn check( &mut self, config: &Config, dns_resolver: R, tls_backend: rustls::ClientConfig, - ) -> crate::Result<()> { + ) -> crate::Result<()> + where + R: reqwest::dns::Resolve + 'static, + { let Some(check_url) = config.checking.check_url.clone() else { return Ok(()); }; @@ -161,11 +164,10 @@ impl Proxy { Ok(()) } - pub fn write_to_sink( - &self, - sink: &mut S, - include_protocol: bool, - ) { + pub fn write_to_sink(&self, sink: &mut S, include_protocol: bool) + where + S: ProxySink, + { if include_protocol { sink.push_str(self.protocol.as_str_lowercase()); sink.push_str("://"); @@ -208,7 +210,10 @@ impl PartialEq for Proxy { #[expect(clippy::missing_trait_methods)] impl Hash for Proxy { - fn hash(&self, state: &mut H) { + fn hash(&self, state: &mut H) + where + H: Hasher, + { self.protocol.hash(state); self.host.hash(state); self.port.hash(state); diff --git a/src/raw_config.rs b/src/raw_config.rs index cbecd80..af150b7 100644 --- a/src/raw_config.rs +++ b/src/raw_config.rs @@ -11,9 +11,10 @@ use crate::{HashMap, http::BasicAuth}; const CONFIG_ENV: &str = "PROXY_SCRAPER_CHECKER_CONFIG"; -fn validate_positive_f64<'de, D: serde::Deserializer<'de>>( - deserializer: D, -) -> Result { +fn validate_positive_f64<'de, D>(deserializer: D) -> Result +where + D: serde::Deserializer<'de>, +{ let val = f64::deserialize(deserializer)?; if val > 0.0 { Ok(val) @@ -67,15 +68,21 @@ where } } -fn validate_proxy_url<'de, D: serde::Deserializer<'de>>( +fn validate_proxy_url<'de, D>( deserializer: D, -) -> Result, D::Error> { +) -> Result, D::Error> +where + D: serde::Deserializer<'de>, +{ validate_url_generic(deserializer, &["http", "https", "socks4", "socks5"]) } -fn validate_http_url<'de, D: serde::Deserializer<'de>>( +fn validate_http_url<'de, D>( deserializer: D, -) -> Result, D::Error> { +) -> Result, D::Error> +where + D: serde::Deserializer<'de>, +{ validate_url_generic(deserializer, &["http", "https"]) } @@ -159,9 +166,10 @@ pub struct RawConfig { #[expect(clippy::missing_trait_methods)] impl<'de> serde::Deserialize<'de> for OutputConfig { - fn deserialize>( - deserializer: D, - ) -> Result { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { #[derive(serde::Deserialize)] struct InnerOutputConfig { pub path: PathBuf, diff --git a/src/utils.rs b/src/utils.rs index 9e925c1..f66759a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -24,7 +24,7 @@ pub trait CompactStrJoin: Iterator { } #[expect(clippy::missing_trait_methods)] -impl CompactStrJoin for T {} +impl CompactStrJoin for T where T: Iterator {} pub fn pretty_error(e: &crate::Error) -> compact_str::CompactString { e.chain().join(" \u{2192} ")