Code change:
This code should be correct, because according to document, all address in are not global reachable. But it panic on assertion failed in latest nightly (2019-01-11) (see )
Relevant thread:
Sorry, fixed

Related discussion:
text: /// use std::net::Ipv4Addr; /// /// fn main() { <ins> ///     // private addresses are not global </ins> ///     assert_eq!(Ipv4Addr::new(10, 254, 0, 0).is_global(), false); ///     assert_eq!(Ipv4Addr::new(192, 168, 10, 65).is_global(), false); ///     assert_eq!(Ipv4Addr::new(172, 16, 10, 65).is_global(), false); <ins> /// ///     // the 0.0.0.0/8 block is not global ///     assert_eq!(Ipv4Addr::new(0, 1, 2, 3).is_global(), false); ///     // in particular, the unspecified address is not global </ins> ///     assert_eq!(Ipv4Addr::new(0, 0, 0, 0).is_global(), false); <ins> /// ///     // the loopback address is not global ///     assert_eq!(Ipv4Addr::new(127, 0, 0, 1).is_global(), false); /// ///     // link local addresses are not global ///     assert_eq!(Ipv4Addr::new(169, 254, 45, 1).is_global(), false); /// ///     // the broadcast address is not global ///     assert_eq!(Ipv4Addr::new(255, 255, 255, 255).is_global(), false); /// ///     // the broadcast address is not global ///     assert_eq!(Ipv4Addr::new(192, 0, 2, 255).is_global(), false); ///     assert_eq!(Ipv4Addr::new(198, 51, 100, 65).is_global(), false); ///     assert_eq!(Ipv4Addr::new(203, 0, 113, 6).is_global(), false); /// ///     // shared addresses are not global ///     assert_eq!(Ipv4Addr::new(100, 100, 0, 0).is_global(), false); /// ///     // addresses reserved for protocol assignment are not global ///     assert_eq!(Ipv4Addr::new(192, 0, 0, 0).is_global(), false); ///     assert_eq!(Ipv4Addr::new(192, 0, 0, 255).is_global(), false); /// ///     // addresses reserved for future use are not global ///     assert_eq!(Ipv4Addr::new(250, 10, 20, 30).is_global(), false); /// ///     // addresses reserved for network devices benchmarking are not global ///     assert_eq!(Ipv4Addr::new(198, 18, 0, 0).is_global(), false); /// ///     // All the other addresses are global ///     assert_eq!(Ipv4Addr::new(1, 1, 1, 1).is_global(), true); </ins> ///     assert_eq!(Ipv4Addr::new(80, 9, 12, 3).is_global(), true); /// } /// ``` pub fn is_global(&self) -> bool { <del> !self.is_private() && !self.is_loopback() && !self.is_link_local() && !self.is_broadcast() && !self.is_documentation() && !self.is_unspecified() </del> <ins> // check if this address is 192.0.0.9 or 192.0.0.10. These addresses are the only two // globally routable addresses in the 192.0.0.0/24 range. if u32::from(*self) == 0xc0000009 || u32::from(*self) == 0xc000000a { return true; } !self.is_private() && !self.is_loopback() && !self.is_link_local() && !self.is_broadcast() && !self.is_documentation() && !self.is_shared() && !self.is_ietf_protocol_assignment() && !self.is_reserved() && !self.is_benchmarking() // Make sure the address is not in 0.0.0.0/8 && self.octets()[0] != 0 } /// 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]. /// /// Note that parts of this block are in use: /// /// - `192.0.0.8/32` is the "IPv4 dummy address" (see [IETF RFC 7600]) /// - `192.0.0.9/32` is the "Port Control Protocol Anycast" (see [IETF RFC 7723]) /// - `192.0.0.10/32` is used for NAT traversal (see [IETF RFC 8155]) /// /// [IETF RFC 6890]: https://tools.ietf.org/html/rfc6890 /// [IETF RFC 7600]: https://tools.ietf.org/html/rfc7600 /// [IETF RFC 7723]: https://tools.ietf.org/html/rfc7723 /// [IETF RFC 8155]: https://tools.ietf.org/html/rfc8155 /// [`true`]: ../../std/primitive.bool.html /// /// # Examples /// /// ``` /// #![feature(ip)] /// use std::net::Ipv4Addr; /// /// fn main() { ///     assert_eq!(Ipv4Addr::new(192, 0, 0, 0).is_ietf_protocol_assignment(), true); ///     assert_eq!(Ipv4Addr::new(192, 0, 0, 8).is_ietf_protocol_assignment(), true); ///     assert_eq!(Ipv4Addr::new(192, 0, 0, 9).is_ietf_protocol_assignment(), true); ///     assert_eq!(Ipv4Addr::new(192, 0, 0, 255).is_ietf_protocol_assignment(), true); ///     assert_eq!(Ipv4Addr::new(192, 0, 1, 0).is_ietf_protocol_assignment(), false); ///     assert_eq!(Ipv4Addr::new(191, 255, 255, 255).is_ietf_protocol_assignment(), false); /// } /// ``` pub fn is_ietf_protocol_assignment(&self) -> bool { self.octets()[0] == 192 && self.octets()[1] == 0 && self.octets()[2] == 0 } /// Returns [`true`] if this address part of the `198.18.0.0/15` range, which is reserved for /// network devices benchmarking. This range is defined in [IETF RFC 2544] as `192.18.0.0` /// through `198.19.255.255` but [errata 423] corrects it to `198.18.0.0/15`. /// /// [IETF RFC 1112]: https://tools.ietf.org/html/rfc1112 /// [errate 423]: https://www.rfc-editor.org/errata/eid423 /// [`true`]: ../../std/primitive.bool.html /// /// # Examples /// /// ``` /// #![feature(ip)] /// use std::net::Ipv4Addr; /// /// fn main() { ///     assert_eq!(Ipv4Addr::new(198, 17, 255, 255).is_benchmarking(), false); ///     assert_eq!(Ipv4Addr::new(198, 18, 0, 0).is_benchmarking(), true); ///     assert_eq!(Ipv4Addr::new(198, 19, 255, 255).is_benchmarking(), true); ///     assert_eq!(Ipv4Addr::new(198, 20, 0, 0).is_benchmarking(), false); /// } /// ``` pub fn is_benchmarking(&self) -> bool { self.octets()[0] == 198 && (self.octets()[1] & 0xfe) == 18 } /// Returns [`true`] if this address is reserved by IANA for future use. [IETF RFC 1112] /// defines the block of reserved addresses as `240.0.0.0/4`. This range normally includes the /// broadcast address `255.255.255.255`, but this implementation explicitely excludes it, since /// it is obviously not reserved for future use. /// /// [IETF RFC 1112]: https://tools.ietf.org/html/rfc1112 /// [`true`]: ../../std/primitive.bool.html /// /// # Examples /// /// ``` /// #![feature(ip)] /// use std::net::Ipv4Addr; /// /// fn main() { ///     assert_eq!(Ipv4Addr::new(240, 0, 0, 0).is_reserved(), true); ///     assert_eq!(Ipv4Addr::new(255, 255, 255, 254).is_reserved(), true); /// ///     assert_eq!(Ipv4Addr::new(239, 255, 255, 255).is_reserved(), false); ///     // The broadcast address is not considered as reserved for future use by this ///     // implementation ///     assert_eq!(Ipv4Addr::new(255, 255, 255, 255).is_reserved(), false); /// } /// ``` pub fn is_reserved(&self) -> bool { self.octets()[0] & 240 == 240 && !self.is_broadcast() </ins> } /// Returns [`true`] if this is a multicast address (224.0.0.0/4).