@@ -232,6 +232,7 @@ impl SocketAddr {
|
||||
/// assert_eq!(socket.is_ipv4(), true);
|
||||
/// assert_eq!(socket.is_ipv6(), false);
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "sockaddr_checker", since = "1.16.0")]
|
||||
#[rustc_const_unstable(feature = "const_socketaddr", issue = "82485")]
|
||||
pub const fn is_ipv4(&self) -> bool {
|
||||
@@ -253,6 +254,7 @@ impl SocketAddr {
|
||||
/// assert_eq!(socket.is_ipv4(), false);
|
||||
/// assert_eq!(socket.is_ipv6(), true);
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "sockaddr_checker", since = "1.16.0")]
|
||||
#[rustc_const_unstable(feature = "const_socketaddr", issue = "82485")]
|
||||
pub const fn is_ipv6(&self) -> bool {
|
||||
|
||||
@@ -233,6 +233,7 @@ impl IpAddr {
|
||||
/// ```
|
||||
#[rustc_const_stable(feature = "const_ip", since = "1.50.0")]
|
||||
#[stable(feature = "ip_shared", since = "1.12.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_unspecified(&self) -> bool {
|
||||
match self {
|
||||
@@ -256,6 +257,7 @@ impl IpAddr {
|
||||
/// ```
|
||||
#[rustc_const_stable(feature = "const_ip", since = "1.50.0")]
|
||||
#[stable(feature = "ip_shared", since = "1.12.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_loopback(&self) -> bool {
|
||||
match self {
|
||||
@@ -281,6 +283,7 @@ impl IpAddr {
|
||||
/// ```
|
||||
#[rustc_const_unstable(feature = "const_ip", issue = "76205")]
|
||||
#[unstable(feature = "ip", issue = "27709")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_global(&self) -> bool {
|
||||
match self {
|
||||
@@ -304,6 +307,7 @@ impl IpAddr {
|
||||
/// ```
|
||||
#[rustc_const_stable(feature = "const_ip", since = "1.50.0")]
|
||||
#[stable(feature = "ip_shared", since = "1.12.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_multicast(&self) -> bool {
|
||||
match self {
|
||||
@@ -332,6 +336,7 @@ impl IpAddr {
|
||||
/// ```
|
||||
#[rustc_const_unstable(feature = "const_ip", issue = "76205")]
|
||||
#[unstable(feature = "ip", issue = "27709")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_documentation(&self) -> bool {
|
||||
match self {
|
||||
@@ -356,6 +361,7 @@ impl IpAddr {
|
||||
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0x2, 0, 0, 0, 0, 0, 0)).is_benchmarking(), true);
|
||||
/// ```
|
||||
#[unstable(feature = "ip", issue = "27709")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_benchmarking(&self) -> bool {
|
||||
match self {
|
||||
@@ -379,6 +385,7 @@ impl IpAddr {
|
||||
/// ```
|
||||
#[rustc_const_stable(feature = "const_ip", since = "1.50.0")]
|
||||
#[stable(feature = "ipaddr_checker", since = "1.16.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_ipv4(&self) -> bool {
|
||||
matches!(self, IpAddr::V4(_))
|
||||
@@ -399,6 +406,7 @@ impl IpAddr {
|
||||
/// ```
|
||||
#[rustc_const_stable(feature = "const_ip", since = "1.50.0")]
|
||||
#[stable(feature = "ipaddr_checker", since = "1.16.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_ipv6(&self) -> bool {
|
||||
matches!(self, IpAddr::V6(_))
|
||||
@@ -527,6 +535,7 @@ impl Ipv4Addr {
|
||||
/// ```
|
||||
#[rustc_const_stable(feature = "const_ipv4", since = "1.32.0")]
|
||||
#[stable(feature = "ip_shared", since = "1.12.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_unspecified(&self) -> bool {
|
||||
self.inner.s_addr == 0
|
||||
@@ -548,6 +557,7 @@ impl Ipv4Addr {
|
||||
/// ```
|
||||
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
|
||||
#[stable(since = "1.7.0", feature = "ip_17")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_loopback(&self) -> bool {
|
||||
self.octets()[0] == 127
|
||||
@@ -578,6 +588,7 @@ impl Ipv4Addr {
|
||||
/// ```
|
||||
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
|
||||
#[stable(since = "1.7.0", feature = "ip_17")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_private(&self) -> bool {
|
||||
match self.octets() {
|
||||
@@ -605,6 +616,7 @@ impl Ipv4Addr {
|
||||
/// ```
|
||||
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
|
||||
#[stable(since = "1.7.0", feature = "ip_17")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_link_local(&self) -> bool {
|
||||
matches!(self.octets(), [169, 254, ..])
|
||||
@@ -680,6 +692,7 @@ impl Ipv4Addr {
|
||||
/// ```
|
||||
#[rustc_const_unstable(feature = "const_ipv4", issue = "76205")]
|
||||
#[unstable(feature = "ip", issue = "27709")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_global(&self) -> bool {
|
||||
// check if this address is 192.0.0.9 or 192.0.0.10. These addresses are the only two
|
||||
@@ -720,6 +733,7 @@ impl Ipv4Addr {
|
||||
/// ```
|
||||
#[rustc_const_unstable(feature = "const_ipv4", issue = "76205")]
|
||||
#[unstable(feature = "ip", issue = "27709")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_shared(&self) -> bool {
|
||||
self.octets()[0] == 100 && (self.octets()[1] & 0b1100_0000 == 0b0100_0000)
|
||||
@@ -745,6 +759,7 @@ impl Ipv4Addr {
|
||||
/// ```
|
||||
#[rustc_const_unstable(feature = "const_ipv4", issue = "76205")]
|
||||
#[unstable(feature = "ip", issue = "27709")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_benchmarking(&self) -> bool {
|
||||
self.octets()[0] == 198 && (self.octets()[1] & 0xfe) == 18
|
||||
@@ -779,6 +794,7 @@ impl Ipv4Addr {
|
||||
/// ```
|
||||
#[rustc_const_unstable(feature = "const_ipv4", issue = "76205")]
|
||||
#[unstable(feature = "ip", issue = "27709")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_reserved(&self) -> bool {
|
||||
self.octets()[0] & 240 == 240 && !self.is_broadcast()
|
||||
@@ -802,6 +818,7 @@ impl Ipv4Addr {
|
||||
/// ```
|
||||
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
|
||||
#[stable(since = "1.7.0", feature = "ip_17")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_multicast(&self) -> bool {
|
||||
self.octets()[0] >= 224 && self.octets()[0] <= 239
|
||||
@@ -823,6 +840,7 @@ impl Ipv4Addr {
|
||||
/// ```
|
||||
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
|
||||
#[stable(since = "1.7.0", feature = "ip_17")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_broadcast(&self) -> bool {
|
||||
u32::from_be_bytes(self.octets()) == u32::from_be_bytes(Self::BROADCAST.octets())
|
||||
@@ -850,6 +868,7 @@ impl Ipv4Addr {
|
||||
/// ```
|
||||
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
|
||||
#[stable(since = "1.7.0", feature = "ip_17")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_documentation(&self) -> bool {
|
||||
match self.octets() {
|
||||
@@ -1291,6 +1310,7 @@ impl Ipv6Addr {
|
||||
/// ```
|
||||
#[rustc_const_stable(feature = "const_ipv6", since = "1.50.0")]
|
||||
#[stable(since = "1.7.0", feature = "ip_17")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_unspecified(&self) -> bool {
|
||||
u128::from_be_bytes(self.octets()) == u128::from_be_bytes(Ipv6Addr::UNSPECIFIED.octets())
|
||||
@@ -1314,6 +1334,7 @@ impl Ipv6Addr {
|
||||
/// ```
|
||||
#[rustc_const_stable(feature = "const_ipv6", since = "1.50.0")]
|
||||
#[stable(since = "1.7.0", feature = "ip_17")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_loopback(&self) -> bool {
|
||||
u128::from_be_bytes(self.octets()) == u128::from_be_bytes(Ipv6Addr::LOCALHOST.octets())
|
||||
@@ -1340,6 +1361,7 @@ impl Ipv6Addr {
|
||||
/// ```
|
||||
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
|
||||
#[unstable(feature = "ip", issue = "27709")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_global(&self) -> bool {
|
||||
match self.multicast_scope() {
|
||||
@@ -1367,6 +1389,7 @@ impl Ipv6Addr {
|
||||
/// ```
|
||||
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
|
||||
#[unstable(feature = "ip", issue = "27709")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_unique_local(&self) -> bool {
|
||||
(self.segments()[0] & 0xfe00) == 0xfc00
|
||||
@@ -1395,6 +1418,7 @@ impl Ipv6Addr {
|
||||
/// ```
|
||||
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
|
||||
#[unstable(feature = "ip", issue = "27709")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_unicast(&self) -> bool {
|
||||
!self.is_multicast()
|
||||
@@ -1446,6 +1470,7 @@ impl Ipv6Addr {
|
||||
/// ```
|
||||
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
|
||||
#[unstable(feature = "ip", issue = "27709")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_unicast_link_local(&self) -> bool {
|
||||
(self.segments()[0] & 0xffc0) == 0xfe80
|
||||
@@ -1470,6 +1495,7 @@ impl Ipv6Addr {
|
||||
/// ```
|
||||
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
|
||||
#[unstable(feature = "ip", issue = "27709")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_documentation(&self) -> bool {
|
||||
(self.segments()[0] == 0x2001) && (self.segments()[1] == 0xdb8)
|
||||
@@ -1492,6 +1518,7 @@ impl Ipv6Addr {
|
||||
/// assert_eq!(Ipv6Addr::new(0x2001, 0x2, 0, 0, 0, 0, 0, 0).is_benchmarking(), true);
|
||||
/// ```
|
||||
#[unstable(feature = "ip", issue = "27709")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_benchmarking(&self) -> bool {
|
||||
(self.segments()[0] == 0x2001) && (self.segments()[1] == 0x2) && (self.segments()[2] == 0)
|
||||
@@ -1529,6 +1556,7 @@ impl Ipv6Addr {
|
||||
/// ```
|
||||
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
|
||||
#[unstable(feature = "ip", issue = "27709")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_unicast_global(&self) -> bool {
|
||||
self.is_unicast()
|
||||
@@ -1590,6 +1618,7 @@ impl Ipv6Addr {
|
||||
/// ```
|
||||
#[rustc_const_stable(feature = "const_ipv6", since = "1.50.0")]
|
||||
#[stable(since = "1.7.0", feature = "ip_17")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn is_multicast(&self) -> bool {
|
||||
(self.segments()[0] & 0xff00) == 0xff00
|
||||
|
||||
Reference in New Issue
Block a user