mirror of
https://github.com/achanda/ipnetwork.git
synced 2025-06-15 00:26:33 +00:00
Use cargo clippy --fix to autofix code
This commit is contained in:

committed by
Abhishek Chanda

parent
dff59ea0a5
commit
b624487f72
@ -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
|
||||
|
10
src/ipv4.rs
10
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}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
10
src/ipv6.rs
10
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}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user