From b624487f72c80bf5291dca9b871350a653d3d1ed Mon Sep 17 00:00:00 2001 From: Abhishek Chanda Date: Fri, 7 Apr 2023 12:04:10 -0500 Subject: [PATCH] Use cargo clippy --fix to autofix code --- src/common.rs | 7 +++---- src/ipv4.rs | 10 +++------- src/ipv6.rs | 10 +++------- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/common.rs b/src/common.rs index ee92984..4b65554 100644 --- a/src/common.rs +++ b/src/common.rs @@ -12,9 +12,9 @@ impl fmt::Display for IpNetworkError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use crate::IpNetworkError::*; match *self { - InvalidAddr(ref s) => write!(f, "invalid address: {}", s), + InvalidAddr(ref s) => write!(f, "invalid address: {s}"), InvalidPrefix => write!(f, "invalid prefix"), - InvalidCidrFormat(ref s) => write!(f, "invalid cidr format: {}", s), + InvalidCidrFormat(ref s) => write!(f, "invalid cidr format: {s}"), } } } @@ -37,8 +37,7 @@ pub fn cidr_parts(cidr: &str) -> Result<(&str, Option<&str>), IpNetworkError> { // Error if cidr has multiple slashes if prefix[1..].find('/').is_some() { Err(IpNetworkError::InvalidCidrFormat(format!( - "CIDR must contain a single '/': {}", - cidr + "CIDR must contain a single '/': {cidr}" ))) } else { // Handle the case when cidr has exactly one slash diff --git a/src/ipv4.rs b/src/ipv4.rs index aaac71f..8cc0399 100644 --- a/src/ipv4.rs +++ b/src/ipv4.rs @@ -194,7 +194,7 @@ impl Ipv4Network { /// ``` #[inline] pub fn contains(&self, ip: Ipv4Addr) -> bool { - let mask = !(0xffff_ffff as u64 >> self.prefix) as u32; + let mask = !(0xffff_ffff_u64 >> self.prefix) as u32; let net = u32::from(self.addr) & mask; (u32::from(ip) & mask) == net } @@ -614,9 +614,7 @@ mod test { assert_eq!( src.is_subnet_of(dest), *val, - "testing with {} and {}", - src, - dest + "testing with {src} and {dest}" ); } } @@ -659,9 +657,7 @@ mod test { assert_eq!( src.is_supernet_of(dest), *val, - "testing with {} and {}", - src, - dest + "testing with {src} and {dest}" ); } } diff --git a/src/ipv6.rs b/src/ipv6.rs index 2a3822f..243b7dd 100644 --- a/src/ipv6.rs +++ b/src/ipv6.rs @@ -267,7 +267,7 @@ impl FromStr for Ipv6Network { let (addr_str, prefix_str) = cidr_parts(s)?; let addr = Ipv6Addr::from_str(addr_str).map_err(|e| IpNetworkError::InvalidAddr(e.to_string()))?; let prefix = parse_prefix(prefix_str.unwrap_or(&IPV6_BITS.to_string()), IPV6_BITS)?; - Ok(Ipv6Network::new(addr, prefix)?) + Ipv6Network::new(addr, prefix) } } @@ -601,9 +601,7 @@ mod test { assert_eq!( src.is_subnet_of(dest), *val, - "testing with {} and {}", - src, - dest + "testing with {src} and {dest}" ); } } @@ -646,9 +644,7 @@ mod test { assert_eq!( src.is_supernet_of(dest), *val, - "testing with {} and {}", - src, - dest + "testing with {src} and {dest}" ); } }