Implement overlaps for both types

This commit is contained in:
Abhishek Chanda
2019-02-06 23:29:46 +00:00
parent 439a0deeb7
commit e7c85b5b81
3 changed files with 43 additions and 1 deletions

View File

@ -121,6 +121,17 @@ impl Ipv6Network {
other.is_subnet_of(self)
}
/// Checks if the given `Ipv6Network` is partly contained in other.
pub fn overlaps(self, other: Ipv6Network) -> bool {
other.contains(self.ip()) || (
other.contains(self.broadcast()) || (
self.contains(other.ip()) || (
self.contains(other.broadcast())
)
)
)
}
/// Returns the mask for this `Ipv6Network`.
/// That means the `prefix` most significant bits will be 1 and the rest 0
///
@ -478,4 +489,12 @@ mod test {
assert_eq!(src.is_supernet_of(dest), *val, "testing with {} and {}", src, dest);
}
}
#[test]
fn test_overlaps() {
let other: Ipv6Network = "2001:DB8:ACAD::1/64".parse().unwrap();
let other2: Ipv6Network = "2001:DB8:ACAD::20:2/64".parse().unwrap();
assert_eq!(other2.overlaps(other), true);
}
}