Enum IpAddr
pub 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
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 IpAddr
const fn is_unspecified(&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 unspecified_from(this: Self) -> SelfReturns the unspecified IP address for the same IP version.
Returns
0.0.0.0for IPv4 and::for IPv6.Use this method when you must bind a socket to an unspecified local address that uses the same IP version as a remote address.
Examples
use ; let ipv4 = V4; assert_eq!; let ipv6 = V6; assert_eq!;const fn is_loopback(&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) -> 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) -> 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) -> 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) -> 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) -> boolReturns
trueif this address is anIPv4address, andfalseotherwise.Examples
use ; assert_eq!; assert_eq!;const fn is_ipv6(&self) -> boolReturns
trueif this address is anIPv6address, andfalseotherwise.Examples
use ; assert_eq!; assert_eq!;const fn to_canonical(&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) -> &[u8]Returns the eight-bit integers this address consists of as a slice.
Examples
use ; assert_eq!; assert_eq!
Trait Implementations
impl Clone for IpAddr
fn clone(&self) -> Self
impl Copy for IpAddr
impl Debug for IpAddr
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result
impl Display for IpAddr
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result
impl Eq for IpAddr
fn assert_fields_are_eq(&self)
impl From<Ipv4Addr> for IpAddr
fn from(ipv4: Ipv4Addr) -> IpAddrCopies this address to a new
IpAddr::V4.Examples
use ; let addr = new; assert_eq!
impl From<Ipv6Addr> for IpAddr
fn from(ipv6: Ipv6Addr) -> IpAddrCopies this address to a new
IpAddr::V6.Examples
use ; let addr = new; assert_eq!;
impl From<[u16; 8]> 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<[u8; 16]> 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<[u8; 4]> for IpAddr
fn from(octets: [u8; 4]) -> IpAddrCreates an
IpAddr::V4from a four element byte array.Examples
use ; let addr = from; assert_eq!;
impl FromStr for IpAddr
type Err = AddrParseError;fn from_str(s: &str) -> Result<IpAddr, AddrParseError>
impl Hash for IpAddr
fn hash<__H: Hasher>(&self, state: &mut __H)
impl Ord for IpAddr
fn cmp(&self, other: &Self) -> Ordering
impl PartialEq for IpAddr
fn eq(&self, other: &Self) -> bool
impl PartialEq<Ipv4Addr> for IpAddr
fn eq(&self, other: &Ipv4Addr) -> bool
impl PartialEq<Ipv6Addr> for IpAddr
fn eq(&self, other: &Ipv6Addr) -> bool
impl PartialOrd for IpAddr
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
impl PartialOrd<Ipv4Addr> for IpAddr
fn partial_cmp(&self, other: &Ipv4Addr) -> Option<Ordering>
impl PartialOrd<Ipv6Addr> for IpAddr
fn partial_cmp(&self, other: &Ipv6Addr) -> Option<Ordering>
impl StructuralPartialEq for IpAddr
impl TrivialClone for IpAddr
Auto Trait Implementations
impl Freeze for IpAddr
impl RefUnwindSafe for IpAddr
impl Send for IpAddr
impl Sync for IpAddr
impl Unpin for IpAddr
impl UnsafeUnpin for IpAddr
impl UnwindSafe for IpAddr
Blanket Implementations
impl<T> Any for IpAddr
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for IpAddr
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for IpAddr
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for IpAddr
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for IpAddr
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Printable for IpAddr
where
T: Copy + Debug,
impl<T> SizeHint for IpAddr
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for IpAddr
impl<T, U> Into<U> for IpAddr
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for IpAddr
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for IpAddr
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>