diff options
| author | Christiaan Dirkx <christiaan@dirkx.email> | 2020-09-07 17:43:48 +0200 |
|---|---|---|
| committer | Christiaan <christiaan@dirkx.email> | 2020-09-23 21:33:39 +0200 |
| commit | 947536fca06e6dc6c3a3dd4ff1f66fc5080e9cbb (patch) | |
| tree | 8321a3515bc1a161482d7f11bed659b01f49c085 /library/std/src/net/ip | |
| parent | a6008fac97f81a3fc51668b0c7fa0e2e6f2a599b (diff) | |
Make delegation methods of `std::net::IpAddr` unstable const
Make the following methods of `std::net::IpAddr` unstable const under the `const_ip` feature: - `is_unspecified` - `is_loopback` - `is_global` - `is_multicast` Also adds a test for these methods in a const context. Possible because these methods delegate to the inner `Ipv4Addr` or `Ipv6Addr`, which were made const, and the recent stabilization of const control flow. Part of #76205
Diffstat (limited to 'library/std/src/net/ip')
| -rw-r--r-- | library/std/src/net/ip/tests.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/library/std/src/net/ip/tests.rs b/library/std/src/net/ip/tests.rs index 76a0ae8b945..d9fbdd1b5e7 100644 --- a/library/std/src/net/ip/tests.rs +++ b/library/std/src/net/ip/tests.rs @@ -918,3 +918,22 @@ fn ipv6_const() { const IP_V4: Option<Ipv4Addr> = IP_ADDRESS.to_ipv4(); assert_eq!(IP_V4.unwrap(), Ipv4Addr::new(0, 0, 0, 1)); } + +#[test] +fn ip_const() { + // test that the methods of `IpAddr` are usable in a const context + + const IP_ADDRESS: IpAddr = IpAddr::V4(Ipv4Addr::LOCALHOST); + + const IS_UNSPECIFIED: bool = IP_ADDRESS.is_unspecified(); + assert!(!IS_UNSPECIFIED); + + const IS_LOOPBACK: bool = IP_ADDRESS.is_loopback(); + assert!(IS_LOOPBACK); + + const IS_GLOBAL: bool = IP_ADDRESS.is_global(); + assert!(!IS_GLOBAL); + + const IS_MULTICAST: bool = IP_ADDRESS.is_multicast(); + assert!(!IS_MULTICAST); +} |
