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

Run clippy manually and cleanup #166

Merged
merged 2 commits into from
Apr 7, 2023
Merged
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
7 changes: 3 additions & 4 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"),
}
}
}
Expand All @@ -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
Expand Down
16 changes: 6 additions & 10 deletions src/ipv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -614,9 +614,7 @@ mod test {
assert_eq!(
src.is_subnet_of(dest),
*val,
"testing with {} and {}",
src,
dest
"testing with {src} and {dest}"
);
}
}
Expand Down Expand Up @@ -659,9 +657,7 @@ mod test {
assert_eq!(
src.is_supernet_of(dest),
*val,
"testing with {} and {}",
src,
dest
"testing with {src} and {dest}"
);
}
}
Expand All @@ -673,9 +669,9 @@ mod test {
let other3: Ipv4Network = "1.2.2.64/26".parse().unwrap();

let skynet: Ipv4Network = "1.2.3.0/24".parse().unwrap();
assert_eq!(skynet.overlaps(other), true);
assert_eq!(skynet.overlaps(other2), false);
assert_eq!(other2.overlaps(other3), true);
assert!(skynet.overlaps(other));
assert!(!skynet.overlaps(other2));
assert!(other2.overlaps(other3));
}

#[test]
Expand Down
10 changes: 3 additions & 7 deletions src/ipv6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -601,9 +601,7 @@ mod test {
assert_eq!(
src.is_subnet_of(dest),
*val,
"testing with {} and {}",
src,
dest
"testing with {src} and {dest}"
);
}
}
Expand Down Expand Up @@ -646,9 +644,7 @@ mod test {
assert_eq!(
src.is_supernet_of(dest),
*val,
"testing with {} and {}",
src,
dest
"testing with {src} and {dest}"
);
}
}
Expand Down