diff --git a/leaf/src/app/router.rs b/leaf/src/app/router.rs index 76a5dd3df..6ea855985 100644 --- a/leaf/src/app/router.rs +++ b/leaf/src/app/router.rs @@ -424,15 +424,15 @@ impl Router { for rr in routing_rules.iter_mut() { let mut cond_and = ConditionAnd::new(); - if rr.domains.len() > 0 { + if !rr.domains.is_empty() { cond_and.add(Box::new(DomainMatcher::new(&mut rr.domains))); } - if rr.ip_cidrs.len() > 0 { + if !rr.ip_cidrs.is_empty() { cond_and.add(Box::new(IpCidrMatcher::new(&mut rr.ip_cidrs))); } - if rr.mmdbs.len() > 0 { + if !rr.mmdbs.is_empty() { for mmdb in rr.mmdbs.iter() { let reader = match mmdb_readers.get(&mmdb.file) { Some(r) => r.clone(), @@ -455,15 +455,15 @@ impl Router { } } - if rr.port_ranges.len() > 0 { + if !rr.port_ranges.is_empty() { cond_and.add(Box::new(PortMatcher::new(&rr.port_ranges))); } - if rr.networks.len() > 0 { + if !rr.networks.is_empty() { cond_and.add(Box::new(NetworkMatcher::new(&mut rr.networks))); } - if rr.inbound_tags.len() > 0 { + if !rr.inbound_tags.is_empty() { cond_and.add(Box::new(InboundTagMatcher::new(&mut rr.inbound_tags))); } diff --git a/leaf/src/common/sniff.rs b/leaf/src/common/sniff.rs index 78b3fface..86e3d7bcc 100644 --- a/leaf/src/common/sniff.rs +++ b/leaf/src/common/sniff.rs @@ -65,7 +65,7 @@ where let bytes_str = String::from_utf8_lossy(buf); let parts: Vec<&str> = bytes_str.split("\r\n").collect(); - if parts.len() == 0 { + if parts.is_empty() { return SniffResult::NotMatch; } @@ -84,7 +84,7 @@ where } for (idx, &el) in parts.iter().enumerate() { - if idx == 0 || el == "" { + if idx == 0 || el.is_empty() { continue; } let inner_parts: Vec<&str> = el.split(":").collect(); diff --git a/leaf/src/config/conf/config.rs b/leaf/src/config/conf/config.rs index 39bc5c0a0..47c1bed1c 100644 --- a/leaf/src/config/conf/config.rs +++ b/leaf/src/config/conf/config.rs @@ -797,7 +797,7 @@ pub fn to_internal(conf: &mut Config) -> Result { for item in ext_always_real_ip { fake_dns_exclude.push(item.clone()) } - if fake_dns_exclude.len() > 0 { + if !fake_dns_exclude.is_empty() { settings.fake_dns_exclude = fake_dns_exclude; } } @@ -807,7 +807,7 @@ pub fn to_internal(conf: &mut Config) -> Result { for item in ext_always_fake_ip { fake_dns_include.push(item.clone()) } - if fake_dns_include.len() > 0 { + if !fake_dns_include.is_empty() { settings.fake_dns_include = fake_dns_include; } } diff --git a/leaf/src/config/json/config.rs b/leaf/src/config/json/config.rs index dd581ddd2..771e3f284 100644 --- a/leaf/src/config/json/config.rs +++ b/leaf/src/config/json/config.rs @@ -347,7 +347,7 @@ pub fn to_internal(json: &mut Config) -> Result { fake_dns_exclude.push(ext_exclude); } } - if fake_dns_exclude.len() > 0 { + if !fake_dns_exclude.is_empty() { settings.fake_dns_exclude = fake_dns_exclude; } @@ -357,7 +357,7 @@ pub fn to_internal(json: &mut Config) -> Result { fake_dns_include.push(ext_include); } } - if fake_dns_include.len() > 0 { + if !fake_dns_include.is_empty() { settings.fake_dns_include = fake_dns_include; } @@ -707,7 +707,7 @@ pub fn to_internal(json: &mut Config) -> Result { alpns.push(ext_alpn); } } - if alpns.len() > 0 { + if !alpns.is_empty() { settings.alpn = alpns; } if let Some(ext_certificate) = ext_settings.certificate { diff --git a/leaf/src/proxy/tls/outbound/stream.rs b/leaf/src/proxy/tls/outbound/stream.rs index 91187e928..0aa6c20e3 100644 --- a/leaf/src/proxy/tls/outbound/stream.rs +++ b/leaf/src/proxy/tls/outbound/stream.rs @@ -137,7 +137,7 @@ impl Handler { } let mut builder = SslConnector::builder(SslMethod::tls()).expect("create ssl connector failed"); - if alpns.len() > 0 { + if !alpns.is_empty() { let wire = alpns .into_iter() .map(|a| [&[a.len() as u8], a.as_bytes()].concat())