Skip to content

Commit 230441e

Browse files
committed
Add IP structural_match tests
1 parent 8cd7351 commit 230441e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

library/std/src/net/ip/tests.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,3 +944,26 @@ fn ip_const() {
944944
const IS_IP_V6: bool = IP_ADDRESS.is_ipv6();
945945
assert!(!IS_IP_V6);
946946
}
947+
948+
#[test]
949+
fn structural_match() {
950+
// test that all IP types can be structurally matched upon
951+
952+
const IPV4: Ipv4Addr = Ipv4Addr::LOCALHOST;
953+
match IPV4 {
954+
Ipv4Addr::LOCALHOST => {}
955+
_ => unreachable!(),
956+
}
957+
958+
const IPV6: Ipv6Addr = Ipv6Addr::LOCALHOST;
959+
match IPV6 {
960+
Ipv6Addr::LOCALHOST => {}
961+
_ => unreachable!(),
962+
}
963+
964+
const IP: IpAddr = IpAddr::V4(Ipv4Addr::LOCALHOST);
965+
match IP {
966+
IpAddr::V4(Ipv4Addr::LOCALHOST) => {}
967+
_ => unreachable!(),
968+
}
969+
}

0 commit comments

Comments
 (0)