Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Optimize code based on cargo clippy suggestions #2167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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