diff options
| author | Linus Färnstrand <faern@faern.net> | 2020-11-29 21:57:14 +0100 |
|---|---|---|
| committer | Linus Färnstrand <faern@faern.net> | 2022-06-23 21:01:58 +0200 |
| commit | 230441e8ab2fed8a03efbf1ccaabe06e922fc61a (patch) | |
| tree | 290839f66d8fb61289758a51581445d8c594c181 | |
| parent | 8cd73519621513fe75b915e8c37c87f128b453dd (diff) | |
| download | rust-230441e8ab2fed8a03efbf1ccaabe06e922fc61a.tar.gz rust-230441e8ab2fed8a03efbf1ccaabe06e922fc61a.zip | |
Add IP structural_match tests
| -rw-r--r-- | library/std/src/net/ip/tests.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/library/std/src/net/ip/tests.rs b/library/std/src/net/ip/tests.rs index 7956c6a25e4..c29509331d7 100644 --- a/library/std/src/net/ip/tests.rs +++ b/library/std/src/net/ip/tests.rs @@ -944,3 +944,26 @@ fn ip_const() { const IS_IP_V6: bool = IP_ADDRESS.is_ipv6(); assert!(!IS_IP_V6); } + +#[test] +fn structural_match() { + // test that all IP types can be structurally matched upon + + const IPV4: Ipv4Addr = Ipv4Addr::LOCALHOST; + match IPV4 { + Ipv4Addr::LOCALHOST => {} + _ => unreachable!(), + } + + const IPV6: Ipv6Addr = Ipv6Addr::LOCALHOST; + match IPV6 { + Ipv6Addr::LOCALHOST => {} + _ => unreachable!(), + } + + const IP: IpAddr = IpAddr::V4(Ipv4Addr::LOCALHOST); + match IP { + IpAddr::V4(Ipv4Addr::LOCALHOST) => {} + _ => unreachable!(), + } +} |
