std::net: add Ipv4Addr::is_shared()
This commit is contained in:
parent
f87b96773b
commit
67291cc971
1 changed files with 22 additions and 0 deletions
|
|
@ -532,6 +532,28 @@ impl Ipv4Addr {
|
|||
!self.is_broadcast() && !self.is_documentation() && !self.is_unspecified()
|
||||
}
|
||||
|
||||
/// Returns [`true`] if this address is part of the Shared Address Space defined in
|
||||
/// [IETF RFC 6598] (`100.64.0.0/10`).
|
||||
///
|
||||
/// [IETF RFC 6598]: https://tools.ietf.org/html/rfc6598
|
||||
/// [`true`]: ../../std/primitive.bool.html
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(ip)]
|
||||
/// use std::net::Ipv4Addr;
|
||||
///
|
||||
/// fn main() {
|
||||
/// assert_eq!(Ipv4Addr::new(100, 64, 0, 0).is_shared(), true);
|
||||
/// assert_eq!(Ipv4Addr::new(100, 127, 255, 255).is_shared(), true);
|
||||
/// assert_eq!(Ipv4Addr::new(100, 128, 0, 0).is_shared(), false);
|
||||
/// }
|
||||
/// ```
|
||||
pub fn is_shared(&self) -> bool {
|
||||
self.octets()[0] == 100 && (self.octets()[1] & 0b1100_0000 == 0b0100_0000)
|
||||
}
|
||||
|
||||
/// Returns [`true`] if this address is part of `192.0.0.0/24`, which is reserved to
|
||||
/// IANA for IETF protocol assignments, as documented in [IETF RFC 6890].
|
||||
///
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue