Enum IpAddr
enum IpAddr
An IP address, either IPv4 or IPv6.
This enum can contain either an Ipv4Addr or an Ipv6Addr, see their
respective documentation for more details.
Examples
use ;
let localhost_v4 = V4;
let localhost_v6 = V6;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Variants
-
V4(Ipv4Addr) An IPv4 address.
-
V6(Ipv6Addr) An IPv6 address.
Implementations
impl IpAddr
const fn is_unspecified(self: &Self) -> boolReturns
truefor the special 'unspecified' address.See the documentation for [
Ipv4Addr::is_unspecified()] and [Ipv6Addr::is_unspecified()] for more details.Examples
use ; assert_eq!; assert_eq!;const fn is_loopback(self: &Self) -> boolReturns
trueif this is a loopback address.See the documentation for [
Ipv4Addr::is_loopback()] and [Ipv6Addr::is_loopback()] for more details.Examples
use ; assert_eq!; assert_eq!;const fn is_global(self: &Self) -> boolReturns
trueif the address appears to be globally routable.See the documentation for [
Ipv4Addr::is_global()] and [Ipv6Addr::is_global()] for more details.Examples
use ; assert_eq!; assert_eq!;const fn is_multicast(self: &Self) -> boolReturns
trueif this is a multicast address.See the documentation for [
Ipv4Addr::is_multicast()] and [Ipv6Addr::is_multicast()] for more details.Examples
use ; assert_eq!; assert_eq!;const fn is_documentation(self: &Self) -> boolReturns
trueif this address is in a range designated for documentation.See the documentation for [
Ipv4Addr::is_documentation()] and [Ipv6Addr::is_documentation()] for more details.Examples
use ; assert_eq!; assert_eq!;const fn is_benchmarking(self: &Self) -> boolReturns
trueif this address is in a range designated for benchmarking.See the documentation for [
Ipv4Addr::is_benchmarking()] and [Ipv6Addr::is_benchmarking()] for more details.Examples
use ; assert_eq!; assert_eq!;const fn is_ipv4(self: &Self) -> boolReturns
trueif this address is anIPv4address, andfalseotherwise.Examples
use ; assert_eq!; assert_eq!;const fn is_ipv6(self: &Self) -> boolReturns
trueif this address is anIPv6address, andfalseotherwise.Examples
use ; assert_eq!; assert_eq!;const fn to_canonical(self: &Self) -> IpAddrConverts this address to an
IpAddr::V4if it is an IPv4-mapped IPv6 address, otherwise returnsselfas-is.Examples
use ; let localhost_v4 = new; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;const fn as_octets(self: &Self) -> &[u8]Returns the eight-bit integers this address consists of as a slice.
Examples
use ; assert_eq!; assert_eq!
impl IpAddr
fn parse_ascii(b: &[u8]) -> Result<Self, AddrParseError>Parse an IP address from a slice of bytes.
use ; let localhost_v4 = V4; let localhost_v6 = V6; assert_eq!; assert_eq!;
impl Clone for IpAddr
fn clone(self: &Self) -> IpAddr
impl Copy for IpAddr
impl Debug for IpAddr
fn fmt(self: &Self, fmt: &mut Formatter<'_>) -> Result
impl Display for IpAddr
fn fmt(self: &Self, fmt: &mut Formatter<'_>) -> Result
impl Eq for IpAddr
impl Freeze for IpAddr
impl From for IpAddr
fn from(octets: [u8; 16]) -> IpAddrCreates an
IpAddr::V6from a sixteen element byte array.Examples
use ; let addr = from; assert_eq!;
impl From for IpAddr
fn from(octets: [u8; 4]) -> IpAddrCreates an
IpAddr::V4from a four element byte array.Examples
use ; let addr = from; assert_eq!;
impl From for IpAddr
fn from(segments: [u16; 8]) -> IpAddrCreates an
IpAddr::V6from an eight element 16-bit array.Examples
use ; let addr = from; assert_eq!;
impl From for IpAddr
fn from(ipv4: Ipv4Addr) -> IpAddrCopies this address to a new
IpAddr::V4.Examples
use ; let addr = new; assert_eq!
impl From for IpAddr
fn from(ipv6: Ipv6Addr) -> IpAddrCopies this address to a new
IpAddr::V6.Examples
use ; let addr = new; assert_eq!;
impl FromStr for IpAddr
fn from_str(s: &str) -> Result<IpAddr, AddrParseError>
impl Hash for IpAddr
fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)
impl Ord for IpAddr
fn cmp(self: &Self, other: &IpAddr) -> Ordering
impl PartialEq for IpAddr
fn eq(self: &Self, other: &Ipv4Addr) -> bool
impl PartialEq for IpAddr
fn eq(self: &Self, other: &IpAddr) -> bool
impl PartialEq for IpAddr
fn eq(self: &Self, other: &Ipv6Addr) -> bool
impl PartialOrd for IpAddr
fn partial_cmp(self: &Self, other: &Ipv4Addr) -> Option<Ordering>
impl PartialOrd for IpAddr
fn partial_cmp(self: &Self, other: &Ipv6Addr) -> Option<Ordering>
impl PartialOrd for IpAddr
fn partial_cmp(self: &Self, other: &IpAddr) -> Option<Ordering>
impl RefUnwindSafe for IpAddr
impl Send for IpAddr
impl StructuralPartialEq for IpAddr
impl Sync for IpAddr
impl Unpin for IpAddr
impl UnsafeUnpin for IpAddr
impl UnwindSafe for IpAddr
impl<T> Any for IpAddr
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for IpAddr
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for IpAddr
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for IpAddr
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for IpAddr
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for IpAddr
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for IpAddr
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for IpAddr
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>