Skip to content

Commit 0ce2f1a

Browse files
committed
add move to closures
1 parent 1e7fb96 commit 0ce2f1a

File tree

10 files changed

+34
-26
lines changed

10 files changed

+34
-26
lines changed

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl Config {
210210
(ProxyType::Socks5, raw_config.socks5),
211211
]
212212
.into_iter()
213-
.filter_map(|(proxy_type, section)| {
213+
.filter_map(move |(proxy_type, section)| {
214214
section.enabled.then_some((proxy_type, section.sources))
215215
})
216216
.collect(),

src/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub async fn get_cache_path() -> color_eyre::Result<PathBuf> {
88
static CACHE: tokio::sync::OnceCell<PathBuf> =
99
tokio::sync::OnceCell::const_new();
1010
Ok(CACHE
11-
.get_or_try_init(async || -> color_eyre::Result<PathBuf> {
11+
.get_or_try_init(async move || -> color_eyre::Result<PathBuf> {
1212
let mut path = tokio::task::spawn_blocking(dirs::cache_dir)
1313
.await
1414
.wrap_err("failed to spawn task to get user's cache directory")?

src/geodb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub async fn download_geodb(
9595
get_geodb_path().await.wrap_err("failed to get GeoDB path")?;
9696

9797
let mut headers = reqwest::header::HeaderMap::new();
98-
if tokio::fs::metadata(&geodb_file).await.is_ok_and(|m| m.is_file()) {
98+
if tokio::fs::metadata(&geodb_file).await.is_ok_and(move |m| m.is_file()) {
9999
if let Some(etag) = read_etag().await.wrap_err("failed to read ETag")? {
100100
headers.insert(reqwest::header::IF_NONE_MATCH, etag);
101101
}

src/output.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn sort_by_timeout(proxy: &Proxy) -> tokio::time::Duration {
2121
fn sort_naturally(proxy: &Proxy) -> (ProxyType, Vec<u8>, u16) {
2222
let host_key = proxy.host.parse::<Ipv4Addr>().map_or_else(
2323
move |_| iter::repeat_n(u8::MAX, 4).chain(proxy.host.bytes()).collect(),
24-
|ip| ip.octets().to_vec(),
24+
move |ip| ip.octets().to_vec(),
2525
);
2626
(proxy.protocol.clone(), host_key, proxy.port)
2727
}
@@ -60,7 +60,7 @@ pub async fn save_proxies(
6060
};
6161

6262
let mut sorted_proxies: Vec<_> = storage.iter().collect();
63-
sorted_proxies.sort_by_key(|p| sort_by_timeout(p));
63+
sorted_proxies.sort_by_key(move |p| sort_by_timeout(p));
6464

6565
let mut proxy_dicts = Vec::with_capacity(sorted_proxies.len());
6666

@@ -87,9 +87,9 @@ pub async fn save_proxies(
8787
password: proxy.password.clone(),
8888
host: proxy.host.clone(),
8989
port: proxy.port,
90-
timeout: proxy
91-
.timeout
92-
.map(|d| (d.as_secs_f64() * 100.0).round() / 100.0_f64),
90+
timeout: proxy.timeout.map(move |d| {
91+
(d.as_secs_f64() * 100.0).round() / 100.0_f64
92+
}),
9393
exit_ip: proxy.exit_ip.clone(),
9494
geolocation,
9595
});
@@ -124,9 +124,9 @@ pub async fn save_proxies(
124124
if config.output_txt {
125125
let mut sorted_proxies: Vec<_> = storage.iter().collect();
126126
if config.sort_by_speed {
127-
sorted_proxies.sort_by_key(|p| sort_by_timeout(p));
127+
sorted_proxies.sort_by_key(move |p| sort_by_timeout(p));
128128
} else {
129-
sorted_proxies.sort_by_key(|p| sort_naturally(p));
129+
sorted_proxies.sort_by_key(move |p| sort_naturally(p));
130130
}
131131
let mut grouped_proxies = storage.get_grouped();
132132

@@ -166,9 +166,9 @@ pub async fn save_proxies(
166166

167167
for (proto, proxies) in &mut grouped_proxies {
168168
if config.sort_by_speed {
169-
proxies.sort_by_key(|p| sort_by_timeout(p));
169+
proxies.sort_by_key(move |p| sort_by_timeout(p));
170170
} else {
171-
proxies.sort_by_key(|p| sort_naturally(p));
171+
proxies.sort_by_key(move |p| sort_naturally(p));
172172
}
173173
let text =
174174
create_proxy_list_str(proxies, anonymous_only, false);

src/parsers.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ use std::sync::LazyLock;
22

33
use color_eyre::eyre::{OptionExt as _, WrapErr as _};
44

5-
pub static PROXY_REGEX: LazyLock<fancy_regex::Regex> = LazyLock::new(|| {
6-
fancy_regex::RegexBuilder::new(
5+
pub static PROXY_REGEX: LazyLock<fancy_regex::Regex> = LazyLock::new(
6+
move || {
7+
fancy_regex::RegexBuilder::new(
78
r"(?:^|[^\dA-Za-z])(?:(?P<protocol>https?|socks[45]):\/\/)?(?:(?P<username>[^\s:@]+):(?P<password>[^\s:@]+)@)?(?P<host>(?:[\-\.\dA-Za-z]+|(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])(?:\.(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])){3})):(?P<port>\d|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])(?=[^\dA-Za-z]|$)",
89
)
910
.case_insensitive(true)
1011
.build()
1112
.unwrap()
12-
});
13+
},
14+
);
1315

14-
static IPV4_REGEX: LazyLock<fancy_regex::Regex> = LazyLock::new(|| {
16+
static IPV4_REGEX: LazyLock<fancy_regex::Regex> = LazyLock::new(move || {
1517
fancy_regex::Regex::new(
1618
r"^(?:[0-9:A-Fa-f]+,)?\s*(?P<host>(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])(?:\.(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])){3})(?::(?:\d|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5]))?\s*$"
1719
).unwrap()

src/raw_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub struct ProxySection {
9999
const CONFIG_ENV_VAR: &str = "PROXY_SCRAPER_CHECKER_CONFIG";
100100

101101
pub fn get_config_path() -> String {
102-
env::var(CONFIG_ENV_VAR).unwrap_or_else(|_| "config.toml".to_owned())
102+
env::var(CONFIG_ENV_VAR).unwrap_or_else(move |_| "config.toml".to_owned())
103103
}
104104

105105
pub async fn read_config(path: &str) -> color_eyre::Result<RawConfig> {

src/scraper.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,12 @@ async fn scrape_one(
102102
.ok_or_eyre("failed to match \"port\" regex capture group")?
103103
.as_str()
104104
.parse()?,
105-
username: capture.name("username").map(|m| m.as_str().to_owned()),
106-
password: capture.name("password").map(|m| m.as_str().to_owned()),
105+
username: capture
106+
.name("username")
107+
.map(move |m| m.as_str().to_owned()),
108+
password: capture
109+
.name("password")
110+
.map(move |m| m.as_str().to_owned()),
107111
timeout: None,
108112
exit_ip: None,
109113
};

src/storage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl ProxyStorage {
2222
let mut groups: HashMap<_, _> = self
2323
.enabled_protocols
2424
.iter()
25-
.map(|p| (p.clone(), Vec::new()))
25+
.map(move |p| (p.clone(), Vec::new()))
2626
.collect();
2727
for proxy in &self.proxies {
2828
if let Some(proxies) = groups.get_mut(&proxy.protocol) {

src/ui/tui.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ fn draw(f: &mut Frame, state: &AppState, logger_state: &TuiWidgetState) {
209209

210210
let proxies_layout = Layout::default()
211211
.direction(Direction::Horizontal)
212-
.constraints(state.sources_total.keys().map(|_| Constraint::Fill(1)))
212+
.constraints(
213+
state.sources_total.keys().map(move |_| Constraint::Fill(1)),
214+
)
213215
.split(outer_layout[2]);
214216

215217
let mut proxy_types: Vec<_> = state.sources_total.keys().collect();
@@ -358,7 +360,7 @@ async fn handle_event(
358360
state
359361
.sources_scraped
360362
.entry(proxy_type)
361-
.and_modify(|c| *c = c.saturating_add(1))
363+
.and_modify(move |c| *c = c.saturating_add(1))
362364
.or_insert(1);
363365
}
364366
AppEvent::TotalProxies(proxy_type, amount) => {
@@ -368,14 +370,14 @@ async fn handle_event(
368370
state
369371
.proxies_checked
370372
.entry(proxy_type)
371-
.and_modify(|c| *c = c.saturating_add(1))
373+
.and_modify(move |c| *c = c.saturating_add(1))
372374
.or_insert(1);
373375
}
374376
AppEvent::ProxyWorking(proxy_type) => {
375377
state
376378
.proxies_working
377379
.entry(proxy_type)
378-
.and_modify(|c| *c = c.saturating_add(1))
380+
.and_modify(move |c| *c = c.saturating_add(1))
379381
.or_insert(1);
380382
}
381383
AppEvent::Done => {

src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub async fn is_docker() -> bool {
55
tokio::sync::OnceCell::const_new();
66

77
*CACHE
8-
.get_or_init(async || {
8+
.get_or_init(async move || {
99
tokio::fs::try_exists("/.dockerenv").await.unwrap_or(false)
1010
})
1111
.await
@@ -17,7 +17,7 @@ pub async fn is_docker() -> bool {
1717
}
1818

1919
pub fn is_http_url(value: &str) -> bool {
20-
url::Url::parse(value).is_ok_and(|parsed_url| {
20+
url::Url::parse(value).is_ok_and(move |parsed_url| {
2121
let scheme = parsed_url.scheme();
2222
(scheme == "http" || scheme == "https")
2323
&& parsed_url.host_str().is_some()

0 commit comments

Comments
 (0)