I have two dependencies which give me the same IP address in different formats - one is Ipv4Addr, the other is the same address represented as an IPv4 mapped IPv6 address in a Ipv6Addr. I need to test if they're the same address but this fails:
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::str::FromStr;
fn main() {
let normal_ipv4_address = IpAddr::V4(Ipv4Addr::from_str("10.255.3.5").unwrap());
let ipv6_mapped_address = IpAddr::V6(Ipv6Addr::from_str("::ffff:10.255.3.5").unwrap());
assert!(normal_ipv4_address.eq(&ipv6_mapped_address))
}
What's the best way to assert that these are, in fact, the same address (without using the nightly-only to_canonical
function on the Ipv6Addr)?