2 Commits

Author SHA1 Message Date
c2812a91a8 chore: release v0.21.1 (#206)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-01-07 12:55:55 -06:00
e1d3ac6de1 Fix for 0::/0 network (#205) 2025-01-06 22:13:12 -06:00
3 changed files with 27 additions and 1 deletions

View File

@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [0.21.1](https://github.com/achanda/ipnetwork/compare/v0.21.0...v0.21.1) - 2025-01-07
### Other
- Fix for 0::/0 network ([#205](https://github.com/achanda/ipnetwork/pull/205))
## [0.21.0](https://github.com/achanda/ipnetwork/compare/v0.20.0...v0.21.0) - 2025-01-06
### Fixed

View File

@ -1,6 +1,6 @@
[package]
name = "ipnetwork"
version = "0.21.0"
version = "0.21.1"
authors = ["Abhishek Chanda <abhishek.becs@gmail.com>", "Linus Färnstrand <faern@faern.net>"]
description = "A library to work with IP CIDRs in Rust"
license = "MIT OR Apache-2.0"

View File

@ -203,6 +203,9 @@ impl Ipv6Network {
pub fn mask(&self) -> Ipv6Addr {
debug_assert!(self.prefix <= IPV6_BITS);
if self.prefix == 0 {
return Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0);
}
let mask = u128::MAX << (IPV6_BITS - self.prefix);
Ipv6Addr::from(mask)
}
@ -279,6 +282,10 @@ impl Ipv6Network {
/// ```
pub fn size(&self) -> u128 {
debug_assert!(self.prefix <= IPV6_BITS);
if self.prefix == 0 {
return u128::MAX;
}
1 << (IPV6_BITS - self.prefix)
}
@ -757,4 +764,17 @@ mod test {
);
assert_eq!(net.nth(net.size()), None);
}
#[test]
fn test_mask_with_prefix_0() {
let network: Ipv6Network = "0::/0".parse().unwrap();
let mask = network.mask();
assert_eq!(mask, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0));
}
#[test]
fn test_size_with_prefix_0() {
let network: Ipv6Network = "0::/0".parse().unwrap();
assert_eq!(network.size(), u128::MAX);
}
}