diff options
| author | Corentin Henry <corentinhenry@gmail.com> | 2018-11-19 09:39:05 -0800 |
|---|---|---|
| committer | Corentin Henry <corentinhenry@gmail.com> | 2019-04-22 16:03:39 +0200 |
| commit | 67291cc9711eb4ceb717dc0860aba499bcdf55f7 (patch) | |
| tree | f9f3fddd139d0943acd606bd926447de1ea7b334 /src/libstd/net | |
| parent | f87b96773b0fbbfa24781c58af7a73b816c7d658 (diff) | |
| download | rust-67291cc9711eb4ceb717dc0860aba499bcdf55f7.tar.gz rust-67291cc9711eb4ceb717dc0860aba499bcdf55f7.zip | |
std::net: add Ipv4Addr::is_shared()
Diffstat (limited to 'src/libstd/net')
| -rw-r--r-- | src/libstd/net/ip.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index 998642f8346..fd6b0061990 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -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]. /// |
