fix: add Copy marker to ProxyType and DbType enums

This commit is contained in:
monosans
2025-08-05 10:41:12 +03:00
parent 3f65101451
commit 279f26a6ea
6 changed files with 21 additions and 20 deletions
+2 -2
View File
@@ -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);
}
+2 -2
View File
@@ -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(
+3 -3
View File
@@ -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"
+2 -2
View File
@@ -27,7 +27,7 @@ fn sort_naturally(proxy: &Proxy) -> (ProxyType, Vec<u8>, 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<ProxyType, Vec<&'a Proxy>> {
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);
+3 -1
View File
@@ -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,
+9 -10
View File
@@ -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")]