From 7167a065d1f7ae99b617ff17c47796ece6aaf680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Sun, 29 Jul 2018 22:24:19 +0200 Subject: [PATCH] Add Ipv4Addr BROADCAST assoc const --- src/libstd/net/ip.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index c8d4dd733ad..2f3994365e0 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -385,6 +385,22 @@ impl Ipv4Addr { issue = "44582")] pub const UNSPECIFIED: Self = Ipv4Addr::new(0, 0, 0, 0); + /// An IPv4 address representing the broadcast address: 255.255.255.255 + /// + /// # Examples + /// + /// ``` + /// #![feature(ip_constructors)] + /// use std::net::Ipv4Addr; + /// + /// let addr = Ipv4Addr::BROADCAST; + /// assert_eq!(addr, Ipv4Addr::new(255, 255, 255, 255)); + /// ``` + #[unstable(feature = "ip_constructors", + reason = "requires greater scrutiny before stabilization", + issue = "44582")] + pub const BROADCAST: Self = Ipv4Addr::new(255, 255, 255, 255); + /// Returns the four eight-bit integers that make up this address. /// /// # Examples @@ -1850,6 +1866,8 @@ mod tests { assert!(Ipv4Addr::LOCALHOST.is_loopback()); assert_eq!(Ipv4Addr::UNSPECIFIED, Ipv4Addr::new(0, 0, 0, 0)); assert!(Ipv4Addr::UNSPECIFIED.is_unspecified()); + assert_eq!(Ipv4Addr::BROADCAST, Ipv4Addr::new(255, 255, 255, 255)); + assert!(Ipv4Addr::BROADCAST.is_broadcast()); } #[test]