Add IpAddr::is_benchmarking
This commit is contained in:
parent
e2d6334191
commit
cbaccc12c7
2 changed files with 36 additions and 3 deletions
|
|
@ -252,6 +252,30 @@ impl IpAddr {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns [`true`] if this address is in a range designated for benchmarking.
|
||||
///
|
||||
/// See the documentation for [`Ipv4Addr::is_benchmarking()`] and
|
||||
/// [`Ipv6Addr::is_benchmarking()`] for more details.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(ip)]
|
||||
///
|
||||
/// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
///
|
||||
/// assert_eq!(IpAddr::V4(Ipv4Addr::new(198, 19, 255, 255)).is_benchmarking(), true);
|
||||
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0x2, 0, 0, 0, 0, 0, 0)).is_benchmarking(), true);
|
||||
/// ```
|
||||
#[unstable(feature = "ip", issue = "27709")]
|
||||
#[inline]
|
||||
pub const fn is_benchmarking(&self) -> bool {
|
||||
match self {
|
||||
IpAddr::V4(ip) => ip.is_benchmarking(),
|
||||
IpAddr::V6(ip) => ip.is_benchmarking(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns [`true`] if this address is an [`IPv4` address], and [`false`]
|
||||
/// otherwise.
|
||||
///
|
||||
|
|
|
|||
|
|
@ -224,6 +224,7 @@ fn ip_properties() {
|
|||
let global: u8 = 1 << 2;
|
||||
let multicast: u8 = 1 << 3;
|
||||
let doc: u8 = 1 << 4;
|
||||
let benchmarking: u8 = 1 << 5;
|
||||
|
||||
if ($mask & unspec) == unspec {
|
||||
assert!(ip!($s).is_unspecified());
|
||||
|
|
@ -254,6 +255,12 @@ fn ip_properties() {
|
|||
} else {
|
||||
assert!(!ip!($s).is_documentation());
|
||||
}
|
||||
|
||||
if ($mask & benchmarking) == benchmarking {
|
||||
assert!(ip!($s).is_benchmarking());
|
||||
} else {
|
||||
assert!(!ip!($s).is_benchmarking());
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
|
|
@ -262,6 +269,7 @@ fn ip_properties() {
|
|||
let global: u8 = 1 << 2;
|
||||
let multicast: u8 = 1 << 3;
|
||||
let doc: u8 = 1 << 4;
|
||||
let benchmarking: u8 = 1 << 5;
|
||||
|
||||
check!("0.0.0.0", unspec);
|
||||
check!("0.0.0.1");
|
||||
|
|
@ -280,9 +288,9 @@ fn ip_properties() {
|
|||
check!("239.255.255.255", global | multicast);
|
||||
check!("255.255.255.255");
|
||||
// make sure benchmarking addresses are not global
|
||||
check!("198.18.0.0");
|
||||
check!("198.18.54.2");
|
||||
check!("198.19.255.255");
|
||||
check!("198.18.0.0", benchmarking);
|
||||
check!("198.18.54.2", benchmarking);
|
||||
check!("198.19.255.255", benchmarking);
|
||||
// make sure addresses reserved for protocol assignment are not global
|
||||
check!("192.0.0.0");
|
||||
check!("192.0.0.255");
|
||||
|
|
@ -313,6 +321,7 @@ fn ip_properties() {
|
|||
check!("ff08::", multicast);
|
||||
check!("ff0e::", global | multicast);
|
||||
check!("2001:db8:85a3::8a2e:370:7334", doc);
|
||||
check!("2001:2::ac32:23ff:21", global | benchmarking);
|
||||
check!("102:304:506:708:90a:b0c:d0e:f10", global);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue