Skip to content

Commit dc59f5d

Browse files
committed
Stabilize IpAddr::is_ipv4 and is_ipv6 as const
Insta-stabilize the methods `is_ipv4` and `is_ipv6` of `IpAddr`. Possible because of the recent stabilization of const control flow. Also adds a test for these methods in a const context.
1 parent 7e95740 commit dc59f5d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

std/src/net/ip.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,9 @@ impl IpAddr {
263263
/// assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_ipv4(), true);
264264
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_ipv4(), false);
265265
/// ```
266+
#[rustc_const_stable(feature = "const_ip", since = "1.48.0")]
266267
#[stable(feature = "ipaddr_checker", since = "1.16.0")]
267-
pub fn is_ipv4(&self) -> bool {
268+
pub const fn is_ipv4(&self) -> bool {
268269
matches!(self, IpAddr::V4(_))
269270
}
270271

@@ -281,8 +282,9 @@ impl IpAddr {
281282
/// assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_ipv6(), false);
282283
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_ipv6(), true);
283284
/// ```
285+
#[rustc_const_stable(feature = "const_ip", since = "1.48.0")]
284286
#[stable(feature = "ipaddr_checker", since = "1.16.0")]
285-
pub fn is_ipv6(&self) -> bool {
287+
pub const fn is_ipv6(&self) -> bool {
286288
matches!(self, IpAddr::V6(_))
287289
}
288290
}

0 commit comments

Comments
 (0)