Skip to content

Commit 31fef24

Browse files
committed
style: fmt and clippy
1 parent d2551d4 commit 31fef24

File tree

5 files changed

+50
-31
lines changed

5 files changed

+50
-31
lines changed

proxrs/src/protocol/hysteria2.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use serde::Deserialize;
77
use serde::Serialize;
88
use serde_json::Error;
99

10-
use crate::protocol::deserialize_u16_or_string;
1110
use crate::protocol::deserialize_from_string;
11+
use crate::protocol::deserialize_u16_or_string;
1212
use crate::protocol::ProxyAdapter;
1313
use crate::protocol::UnsupportedLinkError;
1414

@@ -71,7 +71,12 @@ impl ProxyAdapter for Hysteria2 {
7171
}
7272

7373
fn to_link(&self) -> String {
74-
let mut params = "insecure=".to_string() + if self.skip_cert_verify.unwrap_or(false) { "1" } else { "0" };
74+
let mut params = "insecure=".to_string()
75+
+ if self.skip_cert_verify.unwrap_or(false) {
76+
"1"
77+
} else {
78+
"0"
79+
};
7580
if let Some(sni) = &self.sni {
7681
params += &format!("&sni={}", urlencoding::encode(sni));
7782
}
@@ -93,7 +98,14 @@ impl ProxyAdapter for Hysteria2 {
9398
if let Some(alpn) = &self.alpn {
9499
params += &format!("&alpn={}", alpn.join(","));
95100
}
96-
format!("hysteria2://{}@{}:{}/?{}#{}", &self.password, &self.server, &self.port, &params, urlencoding::encode(&self.name))
101+
format!(
102+
"hysteria2://{}@{}:{}/?{}#{}",
103+
&self.password,
104+
&self.server,
105+
&self.port,
106+
&params,
107+
urlencoding::encode(&self.name)
108+
)
97109
}
98110

99111
/*

proxrs/src/protocol/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,8 @@ where
300300
// 使用 Option<serde_json::Value> 来处理任意类型
301301
let value: Value = Deserialize::deserialize(deserializer)?;
302302
match value {
303-
Value::Number(n) => {
304-
Ok(Some(n.to_string()))
305-
}
306-
Value::String(s) => {
307-
Ok(Some(s))
308-
}
303+
Value::Number(n) => Ok(Some(n.to_string())),
304+
Value::String(s) => Ok(Some(s)),
309305
_ => Err(serde::de::Error::custom("Expected a string")),
310306
}
311307
}

proxrs/src/sub.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl SubManager {
268268
}
269269

270270
// 以名称重新排序
271-
proxies.sort_by(|a, b| a.get_name().cmp(&b.get_name()));
271+
proxies.sort_by(|a, b| a.get_name().cmp(b.get_name()));
272272
}
273273

274274
// 通过配置格式,获取 clash 配置文件内容
@@ -311,7 +311,10 @@ impl SubManager {
311311
for proxy in new_proxies {
312312
if regex.is_match(proxy.get_name()) {
313313
if !removed_default
314-
&& proxies.get(0).is_some_and(|p| p.as_str().unwrap().eq("PROXY")) {
314+
&& proxies
315+
.first()
316+
.is_some_and(|p| p.as_str().unwrap().eq("PROXY"))
317+
{
315318
proxies.remove(0);
316319
removed_default = true;
317320
}
@@ -352,7 +355,7 @@ mod test {
352355
let mut proxies = SubManager::parse_from_path(
353356
"/Users/reajason/RustroverProjects/clash-butler/subs/0c1149d13476bbe3b62eecb7c9b895f4",
354357
)
355-
.unwrap();
358+
.unwrap();
356359
SubManager::unset_proxies_name(&mut proxies);
357360
let content = SubManager::get_clash_config_content(path.to_string(), &proxies).unwrap();
358361
println!("{}", content);
@@ -429,16 +432,12 @@ mod test {
429432

430433
#[tokio::test]
431434
async fn test_rename() {
432-
let urls = vec![
433-
"/Users/reajason/RustroverProjects/clash-butler/clash.yaml"
434-
.to_string(),
435-
];
435+
let urls = vec!["/Users/reajason/RustroverProjects/clash-butler/clash.yaml".to_string()];
436436
let mut proxies = SubManager::get_proxies_from_urls(&urls).await;
437437
SubManager::rename_dup_proxies_name(&mut proxies);
438438
let release_clash_template_path =
439439
"/Users/reajason/RustroverProjects/clash-butler/conf/clash_release.yaml".to_string();
440-
let save_path =
441-
"/Users/reajason/RustroverProjects/clash-butler/clash1.yaml".to_string();
440+
let save_path = "/Users/reajason/RustroverProjects/clash-butler/clash1.yaml".to_string();
442441
SubManager::save_proxies_into_clash_file(&proxies, release_clash_template_path, save_path)
443442
}
444443
}

src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async fn main() {
4343
.with_max_level(Level::INFO)
4444
.finish(),
4545
)
46-
.expect("setting default subscriber failed");
46+
.expect("setting default subscriber failed");
4747
let args = Cli::parse();
4848
let config = Settings::new();
4949
match config {
@@ -215,7 +215,7 @@ async fn run(config: Settings) {
215215
openai_is_ok = true;
216216
}
217217
Err(err) => {
218-
error!("「{}」 openai is not ok, {:#}",node, err)
218+
error!("「{}」 openai is not ok, {:#}", node, err)
219219
}
220220
}
221221

@@ -226,11 +226,12 @@ async fn run(config: Settings) {
226226
claude_is_ok = true;
227227
}
228228
Err(err) => {
229-
error!("「{}」 claude is not ok, {:#}",node, err)
229+
error!("「{}」 claude is not ok, {:#}", node, err)
230230
}
231231
}
232232

233-
let ip_detail_result = ip::get_ip_detail(&proxy_ip, &clash_meta.proxy_url).await;
233+
let ip_detail_result =
234+
ip::get_ip_detail(&proxy_ip, &clash_meta.proxy_url).await;
234235
match ip_detail_result {
235236
Ok(ip_detail) => {
236237
info!("{:?}", ip_detail);

src/website.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
use anyhow::{anyhow, Context, Result};
2-
use reqwest::{Client, StatusCode};
31
use std::time::Duration;
42

3+
use anyhow::anyhow;
4+
use anyhow::Context;
5+
use anyhow::Result;
6+
use reqwest::Client;
7+
use reqwest::StatusCode;
8+
59
const USER_AGENT: &str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36";
610
const TIMEOUT: Duration = Duration::from_secs(5);
711

812
fn build_client(proxy_url: &str) -> Result<Client> {
913
Client::builder()
10-
.proxy(reqwest::Proxy::all(proxy_url)
11-
.context("Failed to create proxy configuration")?)
14+
.proxy(reqwest::Proxy::all(proxy_url).context("Failed to create proxy configuration")?)
1215
.timeout(TIMEOUT)
1316
.build()
1417
.context("Failed to build HTTP client")
@@ -36,8 +39,12 @@ pub async fn claude_is_ok(proxy_url: &str) -> Result<()> {
3639
pub async fn openai_is_ok(proxy_url: &str) -> Result<()> {
3740
let url = "https://auth.openai.com/favicon.ico";
3841
let client = build_client(proxy_url)?;
39-
let resp = client.get(url).header("User-Agent", USER_AGENT)
40-
.send().await.with_context(|| "Failed to send request to OpenAI")?;
42+
let resp = client
43+
.get(url)
44+
.header("User-Agent", USER_AGENT)
45+
.send()
46+
.await
47+
.with_context(|| "Failed to send request to OpenAI")?;
4148
let status = resp.status();
4249
if status == StatusCode::OK {
4350
return Ok(());
@@ -49,8 +56,12 @@ pub async fn openai_is_ok(proxy_url: &str) -> Result<()> {
4956
pub async fn youtube_music_is_ok(proxy_url: &str) -> Result<bool> {
5057
let url = "https://music.youtube.com/generate_204";
5158
let client = build_client(proxy_url)?;
52-
let resp = client.head(url).header("User-Agent", USER_AGENT)
53-
.send().await.with_context(|| "Failed to send request to OpenAI")?;
59+
let resp = client
60+
.head(url)
61+
.header("User-Agent", USER_AGENT)
62+
.send()
63+
.await
64+
.with_context(|| "Failed to send request to OpenAI")?;
5465
let status = resp.status();
5566
if status == StatusCode::NO_CONTENT {
5667
return Ok(true);
@@ -69,4 +80,4 @@ mod test {
6980
let result = super::openai_is_ok("http://localhost:7890").await;
7081
println!("{:#?}", result);
7182
}
72-
}
83+
}

0 commit comments

Comments
 (0)