diff --git a/src/checker.rs b/src/checker.rs index 32bdb33..b181b66 100644 --- a/src/checker.rs +++ b/src/checker.rs @@ -47,13 +47,13 @@ pub async fn check_all( let check_result = proxy.check(&config).await; #[cfg(feature = "tui")] drop(tx.send(Event::App(AppEvent::ProxyChecked( - proxy.protocol.clone(), + proxy.protocol, )))); match check_result { Ok(()) => { #[cfg(feature = "tui")] drop(tx.send(Event::App(AppEvent::ProxyWorking( - proxy.protocol.clone(), + proxy.protocol, )))); checked_proxies.lock().await.push(proxy); } diff --git a/src/config.rs b/src/config.rs index 14ab183..bb7b369 100644 --- a/src/config.rs +++ b/src/config.rs @@ -99,8 +99,8 @@ impl Config { self.scraping.sources.keys() } - pub fn protocol_is_enabled(&self, protocol: &ProxyType) -> bool { - self.scraping.sources.contains_key(protocol) + pub fn protocol_is_enabled(&self, protocol: ProxyType) -> bool { + self.scraping.sources.contains_key(&protocol) } pub async fn from_raw_config( diff --git a/src/ipdb.rs b/src/ipdb.rs index 9f05535..22fff23 100644 --- a/src/ipdb.rs +++ b/src/ipdb.rs @@ -7,21 +7,21 @@ use tokio::io::AsyncWriteExt as _; use crate::event::{AppEvent, Event}; use crate::{fs::get_cache_path, utils::is_docker}; -#[derive(Clone)] +#[derive(Clone, Copy)] pub enum DbType { Asn, Geo, } impl DbType { - const fn name(&self) -> &'static str { + const fn name(self) -> &'static str { match self { Self::Asn => "ASN", Self::Geo => "geolocation", } } - const fn url(&self) -> &'static str { + const fn url(self) -> &'static str { match self { Self::Asn => { "https://raw.githubusercontent.com/P3TERX/GeoLite.mmdb/download/GeoLite2-ASN.mmdb" diff --git a/src/output.rs b/src/output.rs index cd898dc..646c2ff 100644 --- a/src/output.rs +++ b/src/output.rs @@ -27,7 +27,7 @@ fn sort_naturally(proxy: &Proxy) -> (ProxyType, Vec, u16) { move |_| iter::repeat_n(u8::MAX, 4).chain(proxy.host.bytes()).collect(), |ip| ip.octets().to_vec(), ); - (proxy.protocol.clone(), host_key, proxy.port) + (proxy.protocol, host_key, proxy.port) } #[derive(serde::Serialize)] @@ -48,7 +48,7 @@ fn group_proxies<'a>( proxies: &'a [Proxy], ) -> HashMap> { let mut groups: HashMap<_, _> = - config.enabled_protocols().cloned().map(|p| (p, Vec::new())).collect(); + config.enabled_protocols().copied().map(|p| (p, Vec::new())).collect(); for proxy in proxies { if let Some(proxies) = groups.get_mut(&proxy.protocol) { proxies.push(proxy); diff --git a/src/proxy.rs b/src/proxy.rs index 3b10d69..b1feb17 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -11,7 +11,9 @@ use crate::{ parsers::parse_ipv4, }; -#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Serialize)] +#[derive( + Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Serialize, +)] #[serde(rename_all = "lowercase")] pub enum ProxyType { Http, diff --git a/src/scraper.rs b/src/scraper.rs index 3adc6c3..5468076 100644 --- a/src/scraper.rs +++ b/src/scraper.rs @@ -42,7 +42,7 @@ async fn scrape_one( }; #[cfg(feature = "tui")] - drop(tx.send(Event::App(AppEvent::SourceScraped(proto.clone())))); + drop(tx.send(Event::App(AppEvent::SourceScraped(proto)))); let text = match text_result { Ok(text) => text, @@ -77,11 +77,11 @@ async fn scrape_one( for capture in matches { let protocol = match capture.name("protocol") { Some(m) => m.as_str().parse()?, - None => proto.clone(), + None => proto, }; - if config.protocol_is_enabled(&protocol) { + if config.protocol_is_enabled(protocol) { #[cfg(feature = "tui")] - seen_protocols.insert(protocol.clone()); + seen_protocols.insert(protocol); proxies.insert(Proxy { protocol, host: capture @@ -125,14 +125,13 @@ pub async fn scrape_all( let mut join_set = tokio::task::JoinSet::new(); for (proto, sources) in &config.scraping.sources { #[cfg(feature = "tui")] - drop(tx.send(Event::App(AppEvent::SourcesTotal( - proto.clone(), - sources.len(), - )))); + drop( + tx.send(Event::App(AppEvent::SourcesTotal(*proto, sources.len()))), + ); for source in sources.iter().cloned() { let config = Arc::clone(&config); let http_client = http_client.clone(); - let proto = proto.clone(); + let proto_copy = *proto; let proxies = Arc::clone(&proxies); let token = token.clone(); #[cfg(feature = "tui")] @@ -143,7 +142,7 @@ pub async fn scrape_all( res = scrape_one( config, http_client, - proto, + proto_copy, proxies, source, #[cfg(feature = "tui")]