From ef89151988483944502a1d5b2725e678c111181d Mon Sep 17 00:00:00 2001 From: bishtpawan Date: Wed, 10 Mar 2021 21:44:46 +0530 Subject: [PATCH 1/2] Improve code readability and quality by: 1. Use of range operator for comparison 2. Use of collapsible_match --- src/connect.rs | 2 +- src/proxy.rs | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/connect.rs b/src/connect.rs index 5413acbfd..fdd4df0fb 100644 --- a/src/connect.rs +++ b/src/connect.rs @@ -1005,7 +1005,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{:02x}", c)?; diff --git a/src/proxy.rs b/src/proxy.rs index f2afabe42..7d34897d5 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -279,11 +279,8 @@ impl Proxy { // Custom *may* match 'http', so assume so. | Intercept::Custom(_) => true, Intercept::System(ref system) => { - if let Some(proxy) = system.get("http") { - match proxy { - ProxyScheme::Http { auth, .. } => auth.is_some(), - _ => false, - } + if let Some(ProxyScheme::Http { auth, .. }) = system.get("http") { + auth.is_some() } else { false } @@ -732,11 +729,10 @@ fn get_sys_proxies( RegistryProxyValues, >, ) -> SystemProxyMap { - let proxies = get_from_environment(); - // TODO: move the following #[cfg] to `if expression` when attributes on `if` expressions allowed #[cfg(target_os = "windows")] { + let proxies = get_from_environment(); if proxies.is_empty() { // don't care errors if can't get proxies from registry, just return an empty HashMap. if let Some(registry_values) = registry_values { @@ -744,7 +740,7 @@ fn get_sys_proxies( } } } - proxies + get_from_environment() } fn insert_proxy(proxies: &mut SystemProxyMap, scheme: impl Into, addr: String) -> bool { From af9dbebe2a707fadc36bf95cc6246973d46bef18 Mon Sep 17 00:00:00 2001 From: bishtpawan Date: Wed, 17 Mar 2021 18:42:07 +0530 Subject: [PATCH 2/2] Resolve PR comments --- src/connect.rs | 2 +- src/proxy.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/connect.rs b/src/connect.rs index fdd4df0fb..5413acbfd 100644 --- a/src/connect.rs +++ b/src/connect.rs @@ -1005,7 +1005,7 @@ mod verbose { } else if c == b'\0' { write!(f, "\\0")?; // ASCII printable - } else if (0x20..0x7f).contains(&c) { + } else if c >= 0x20 && c < 0x7f { write!(f, "{}", c as char)?; } else { write!(f, "\\x{:02x}", c)?; diff --git a/src/proxy.rs b/src/proxy.rs index 7d34897d5..378b60caa 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -729,10 +729,11 @@ fn get_sys_proxies( RegistryProxyValues, >, ) -> SystemProxyMap { + let proxies = get_from_environment(); + // TODO: move the following #[cfg] to `if expression` when attributes on `if` expressions allowed #[cfg(target_os = "windows")] { - let proxies = get_from_environment(); if proxies.is_empty() { // don't care errors if can't get proxies from registry, just return an empty HashMap. if let Some(registry_values) = registry_values { @@ -740,7 +741,7 @@ fn get_sys_proxies( } } } - get_from_environment() + proxies } fn insert_proxy(proxies: &mut SystemProxyMap, scheme: impl Into, addr: String) -> bool {