Rollup merge of #112606 - clarfonthey:ip-display, r=thomcc
Alter `Display` for `Ipv6Addr` for IPv4-compatible addresses ACP: rust-lang/libs-team#239
This commit is contained in:
commit
e24fe97bd9
4 changed files with 7 additions and 13 deletions
|
@ -1770,14 +1770,8 @@ impl fmt::Display for Ipv6Addr {
|
|||
f.write_str("::")
|
||||
} else if self.is_loopback() {
|
||||
f.write_str("::1")
|
||||
} else if let Some(ipv4) = self.to_ipv4() {
|
||||
match segments[5] {
|
||||
// IPv4 Compatible address
|
||||
0 => write!(f, "::{}", ipv4),
|
||||
// IPv4 Mapped address
|
||||
0xffff => write!(f, "::ffff:{}", ipv4),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
} else if let Some(ipv4) = self.to_ipv4_mapped() {
|
||||
write!(f, "::ffff:{}", ipv4)
|
||||
} else {
|
||||
#[derive(Copy, Clone, Default)]
|
||||
struct Span {
|
||||
|
|
|
@ -139,7 +139,7 @@ fn ipv6_addr_to_string() {
|
|||
|
||||
// ipv4-compatible address
|
||||
let a1 = Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0xc000, 0x280);
|
||||
assert_eq!(a1.to_string(), "::192.0.2.128");
|
||||
assert_eq!(a1.to_string(), "::c000:280");
|
||||
|
||||
// v6 address with no zero segments
|
||||
assert_eq!(Ipv6Addr::new(8, 9, 10, 11, 12, 13, 14, 15).to_string(), "8:9:a:b:c:d:e:f");
|
||||
|
@ -316,7 +316,7 @@ fn ip_properties() {
|
|||
|
||||
check!("::", unspec);
|
||||
check!("::1", loopback);
|
||||
check!("::0.0.0.2", global);
|
||||
check!("::2", global);
|
||||
check!("1::", global);
|
||||
check!("fc00::");
|
||||
check!("fdff:ffff::");
|
||||
|
@ -607,7 +607,7 @@ fn ipv6_properties() {
|
|||
|
||||
check!("::1", &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], loopback);
|
||||
|
||||
check!("::0.0.0.2", &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], global | unicast_global);
|
||||
check!("::2", &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], global | unicast_global);
|
||||
|
||||
check!("1::", &[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], global | unicast_global);
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ fn ipv6_socket_addr_to_string() {
|
|||
// IPv4-compatible address.
|
||||
assert_eq!(
|
||||
SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0xc000, 0x280), 8080, 0, 0).to_string(),
|
||||
"[::192.0.2.128]:8080"
|
||||
"[::c000:280]:8080"
|
||||
);
|
||||
|
||||
// IPv6 address with no zero segments.
|
||||
|
|
|
@ -85,7 +85,7 @@ fn ipv6_socket_addr_to_string() {
|
|||
// IPv4-compatible address.
|
||||
assert_eq!(
|
||||
SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0xc000, 0x280), 8080, 0, 0).to_string(),
|
||||
"[::192.0.2.128]:8080"
|
||||
"[::c000:280]:8080"
|
||||
);
|
||||
|
||||
// IPv6 address with no zero segments.
|
||||
|
|
Loading…
Add table
Reference in a new issue