Skip to content

Commit

Permalink
refactor: Optimize code based on cargo clippy suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: tgolang <seekseat@aliyun.com>
  • Loading branch information
tgolang committed Apr 28, 2024
1 parent 2c11ef0 commit 3b5039e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ mod verbose {
} else if c == b'\0' {
write!(f, "\\0")?;
// ASCII printable
} else if c >= 0x20 && c < 0x7f {
} else if (0x20..0x7f).contains(&c) {
write!(f, "{}", c as char)?;
} else {
write!(f, "\\x{c:02x}")?;
Expand Down
2 changes: 1 addition & 1 deletion src/into_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<'a> IntoUrlSealed for &'a String {
}
}

impl<'a> IntoUrlSealed for String {
impl IntoUrlSealed for String {
fn into_url(self) -> crate::Result<Url> {
(&*self).into_url()
}
Expand Down
38 changes: 18 additions & 20 deletions src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,11 @@ impl<S: IntoUrl> IntoProxyScheme for S {
let mut source = e.source();
while let Some(err) = source {
if let Some(parse_error) = err.downcast_ref::<url::ParseError>() {
match parse_error {
url::ParseError::RelativeUrlWithoutBase => {
presumed_to_have_scheme = false;
break;
}
_ => {}
if parse_error == url::ParseError::RelativeUrlWithoutBase {
presumed_to_have_scheme = false;
break;
}
} else if let Some(_) = err.downcast_ref::<crate::error::BadScheme>() {
} else if err.downcast_ref::<crate::error::BadScheme>().is_some() {
presumed_to_have_scheme = false;
break;
}
Expand Down Expand Up @@ -657,12 +654,12 @@ impl ProxyScheme {
match self {
ProxyScheme::Http { ref mut auth, .. } => {
if auth.is_none() {
*auth = update.clone();
auth.clone_from(update);
}
}
ProxyScheme::Https { ref mut auth, .. } => {
if auth.is_none() {
*auth = update.clone();
auth.clone_from(update);
}
}
#[cfg(feature = "socks")]
Expand Down Expand Up @@ -1029,10 +1026,10 @@ fn get_from_platform() -> Option<String> {
#[cfg(any(target_os = "windows", target_os = "macos"))]
fn parse_platform_values_impl(platform_values: String) -> SystemProxyMap {
let mut proxies = HashMap::new();
if platform_values.contains("=") {
if platform_values.contains('=') {
// per-protocol settings.
for p in platform_values.split(";") {
let protocol_parts: Vec<&str> = p.split("=").collect();
for p in platform_values.split(';') {
let protocol_parts: Vec<&str> = p.split('=').collect();
match protocol_parts.as_slice() {
[protocol, address] => {
// If address doesn't specify an explicit protocol as protocol://address
Expand All @@ -1053,16 +1050,15 @@ fn parse_platform_values_impl(platform_values: String) -> SystemProxyMap {
}
}
}
} else if let Some(scheme) = extract_type_prefix(&platform_values) {
// Explicit protocol has been specified
insert_proxy(&mut proxies, scheme, platform_values.to_owned());
} else {
if let Some(scheme) = extract_type_prefix(&platform_values) {
// Explicit protocol has been specified
insert_proxy(&mut proxies, scheme, platform_values.to_owned());
} else {
// No explicit protocol has been specified, default to HTTP
insert_proxy(&mut proxies, "http", format!("http://{platform_values}"));
insert_proxy(&mut proxies, "https", format!("http://{platform_values}"));
}
// No explicit protocol has been specified, default to HTTP
insert_proxy(&mut proxies, "http", format!("http://{platform_values}"));
insert_proxy(&mut proxies, "https", format!("http://{platform_values}"));
}

proxies
}

Expand Down Expand Up @@ -1850,6 +1846,7 @@ mod test {
Proxy::http("ldap%5Cgremlin:pass%3Bword@proxy.example.com:8080").unwrap();
}
}

mod and_url_has_bad {
use super::super::check_parse_error;

Expand Down Expand Up @@ -1945,6 +1942,7 @@ mod test {
.unwrap();
}
}

mod and_url_has_bad {
use super::super::check_parse_error;

Expand Down

0 comments on commit 3b5039e

Please sign in to comment.