Lines Matching defs:IpAddr

7 //! This defines `IpAddr`, `Ipv4Addr`, and `Ipv6Addr`. Ideally, these should be
25 /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
27 /// let localhost_v4 = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
28 /// let localhost_v6 = IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1));
38 pub enum IpAddr {
52 /// See [`IpAddr`] for a type encompassing both IPv4 and IPv6 addresses.
93 /// See [`IpAddr`] for a type encompassing both IPv4 and IPv6 addresses.
221 impl IpAddr {
230 /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
232 /// assert_eq!(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)).is_unspecified(), true);
233 /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)).is_unspecified(), true);
244 IpAddr::V4(ip) => ip.is_unspecified(),
245 IpAddr::V6(ip) => ip.is_unspecified(),
257 /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
259 /// assert_eq!(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)).is_loopback(), true);
260 /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1)).is_loopback(), true);
271 IpAddr::V4(ip) => ip.is_loopback(),
272 IpAddr::V6(ip) => ip.is_loopback(),
286 /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
288 /// assert_eq!(IpAddr::V4(Ipv4Addr::new(80, 9, 12, 3)).is_global(), true);
289 /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0x1c9, 0, 0, 0xafc8, 0, 0x1)).is_global(), true);
300 IpAddr::V4(ip) => ip.is_global(),
301 IpAddr::V6(ip) => ip.is_global(),
313 /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
315 /// assert_eq!(IpAddr::V4(Ipv4Addr::new(224, 254, 0, 0)).is_multicast(), true);
316 /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0)).is_multicast(), true);
327 IpAddr::V4(ip) => ip.is_multicast(),
328 IpAddr::V6(ip) => ip.is_multicast(),
342 /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
344 /// assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_documentation(), true);
346 /// IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_documentation(),
359 IpAddr::V4(ip) => ip.is_documentation(),
360 IpAddr::V6(ip) => ip.is_documentation(),
374 /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
376 /// assert_eq!(IpAddr::V4(Ipv4Addr::new(198, 19, 255, 255)).is_benchmarking(), true);
377 /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0x2, 0, 0, 0, 0, 0, 0)).is_benchmarking(), true);
384 IpAddr::V4(ip) => ip.is_benchmarking(),
385 IpAddr::V6(ip) => ip.is_benchmarking(),
392 /// [`IPv4` address]: IpAddr::V4
397 /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
399 /// assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_ipv4(), true);
400 /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_ipv4(), false);
410 matches!(self, IpAddr::V4(_))
416 /// [`IPv6` address]: IpAddr::V6
421 /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
423 /// assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_ipv6(), false);
424 /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_ipv6(), true);
434 matches!(self, IpAddr::V6(_))
437 /// Converts this address to an `IpAddr::V4` if it is an IPv4-mapped IPv6 addresses, otherwise it
444 /// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
446 /// assert_eq!(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)).to_canonical().is_loopback(), true);
447 /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1)).is_loopback(), false);
448 /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1)).to_canonical().is_loopback(), true);
458 pub const fn to_canonical(&self) -> IpAddr {
460 &v4 @ IpAddr::V4(_) => v4,
461 IpAddr::V6(v6) => v6.to_canonical(),
1009 impl From<Ipv4Addr> for IpAddr {
1010 /// Copies this address to a new `IpAddr::V4`.
1015 /// use std::net::{IpAddr, Ipv4Addr};
1020 /// IpAddr::V4(addr),
1021 /// IpAddr::from(addr)
1025 fn from(ipv4: Ipv4Addr) -> IpAddr {
1026 IpAddr::V4(ipv4)
1031 impl From<Ipv6Addr> for IpAddr {
1032 /// Copies this address to a new `IpAddr::V6`.
1037 /// use std::net::{IpAddr, Ipv6Addr};
1042 /// IpAddr::V6(addr),
1043 /// IpAddr::from(addr)
1047 fn from(ipv6: Ipv6Addr) -> IpAddr {
1048 IpAddr::V6(ipv6)
1053 impl PartialEq<Ipv4Addr> for IpAddr {
1057 IpAddr::V4(v4) => v4 == other,
1058 IpAddr::V6(_) => false,
1064 impl PartialEq<IpAddr> for Ipv4Addr {
1066 fn eq(&self, other: &IpAddr) -> bool {
1068 IpAddr::V4(v4) => self == v4,
1069 IpAddr::V6(_) => false,
1083 impl PartialOrd<Ipv4Addr> for IpAddr {
1087 IpAddr::V4(v4) => v4.partial_cmp(other),
1088 IpAddr::V6(_) => Some(Ordering::Greater),
1094 impl PartialOrd<IpAddr> for Ipv4Addr {
1096 fn partial_cmp(&self, other: &IpAddr) -> Option<Ordering> {
1098 IpAddr::V4(v4) => self.partial_cmp(v4),
1099 IpAddr::V6(_) => Some(Ordering::Less),
1169 impl From<[u8; 4]> for IpAddr {
1170 /// Creates an `IpAddr::V4` from a four element byte array.
1175 /// use std::net::{IpAddr, Ipv4Addr};
1177 /// let addr = IpAddr::from([13u8, 12u8, 11u8, 10u8]);
1178 /// assert_eq!(IpAddr::V4(Ipv4Addr::new(13, 12, 11, 10)), addr);
1181 fn from(octets: [u8; 4]) -> IpAddr {
1182 IpAddr::V4(Ipv4Addr::from(octets))
1793 /// Converts this address to an `IpAddr::V4` if it is an IPv4-mapped addresses, otherwise it
1794 /// returns self wrapped in an `IpAddr::V6`.
1813 pub const fn to_canonical(&self) -> IpAddr {
1815 return IpAddr::V4(mapped);
1817 IpAddr::V6(*self)
1841 impl PartialEq<IpAddr> for Ipv6Addr {
1843 fn eq(&self, other: &IpAddr) -> bool {
1845 IpAddr::V4(_) => false,
1846 IpAddr::V6(v6) => self == v6,
1852 impl PartialEq<Ipv6Addr> for IpAddr {
1856 IpAddr::V4(_) => false,
1857 IpAddr::V6(v6) => v6 == other,
1871 impl PartialOrd<Ipv6Addr> for IpAddr {
1875 IpAddr::V4(_) => Some(Ordering::Less),
1876 IpAddr::V6(v6) => v6.partial_cmp(other),
1882 impl PartialOrd<IpAddr> for Ipv6Addr {
1884 fn partial_cmp(&self, other: &IpAddr) -> Option<Ordering> {
1886 IpAddr::V4(_) => Some(Ordering::Greater),
1887 IpAddr::V6(v6) => self.partial_cmp(v6),
2003 impl From<[u8; 16]> for IpAddr {
2004 /// Creates an `IpAddr::V6` from a sixteen element byte array.
2009 /// use std::net::{IpAddr, Ipv6Addr};
2011 /// let addr = IpAddr::from([
2016 /// IpAddr::V6(Ipv6Addr::new(
2026 fn from(octets: [u8; 16]) -> IpAddr {
2027 IpAddr::V6(Ipv6Addr::from(octets))
2032 impl From<[u16; 8]> for IpAddr {
2033 /// Creates an `IpAddr::V6` from an eight element 16-bit array.
2038 /// use std::net::{IpAddr, Ipv6Addr};
2040 /// let addr = IpAddr::from([
2045 /// IpAddr::V6(Ipv6Addr::new(
2055 fn from(segments: [u16; 8]) -> IpAddr {
2056 IpAddr::V6(Ipv6Addr::from(segments))