Enum SocketAddr
enum SocketAddr
An internet socket address, either IPv4 or IPv6.
Internet socket addresses consist of an IP address, a 16-bit port number, as well
as possibly some version-dependent additional information. See SocketAddrV4's and
SocketAddrV6's respective documentation for more details.
Portability
SocketAddr is intended to be a portable representation of socket addresses and is likely not
the same as the internal socket address type used by the target operating system's API. Like all
repr(Rust) structs, however, its exact layout remains undefined and should not be relied upon
between builds.
Examples
use ;
let socket = new;
assert_eq!;
assert_eq!;
assert_eq!;
Variants
-
V4(SocketAddrV4) An IPv4 socket address.
-
V6(SocketAddrV6) An IPv6 socket address.
Implementations
impl SocketAddr
fn parse_ascii(b: &[u8]) -> Result<Self, AddrParseError>Parse a socket address from a slice of bytes.
use ; let socket_v4 = new; let socket_v6 = new; assert_eq!; assert_eq!;
impl SocketAddr
const fn new(ip: IpAddr, port: u16) -> SocketAddrCreates a new socket address from an IP address and a port number.
Examples
use ; let socket = new; assert_eq!; assert_eq!;const fn ip(self: &Self) -> IpAddrReturns the IP address associated with this socket address.
Examples
use ; let socket = new; assert_eq!;const fn set_ip(self: &mut Self, new_ip: IpAddr)Changes the IP address associated with this socket address.
Examples
use ; let mut socket = new; socket.set_ip; assert_eq!;const fn port(self: &Self) -> u16Returns the port number associated with this socket address.
Examples
use ; let socket = new; assert_eq!;const fn set_port(self: &mut Self, new_port: u16)Changes the port number associated with this socket address.
Examples
use ; let mut socket = new; socket.set_port; assert_eq!;const fn is_ipv4(self: &Self) -> boolReturns
trueif the IP address in thisSocketAddris anIPv4address, andfalseotherwise.Examples
use ; let socket = new; assert_eq!; assert_eq!;const fn is_ipv6(self: &Self) -> boolReturns
trueif the IP address in thisSocketAddris anIPv6address, andfalseotherwise.Examples
use ; let socket = new; assert_eq!; assert_eq!;
impl Clone for SocketAddr
fn clone(self: &Self) -> SocketAddr
impl Copy for SocketAddr
impl Debug for SocketAddr
fn fmt(self: &Self, fmt: &mut Formatter<'_>) -> Result
impl Display for SocketAddr
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Eq for SocketAddr
impl Freeze for SocketAddr
impl From for SocketAddr
fn from(sock4: SocketAddrV4) -> SocketAddrConverts a
SocketAddrV4into aSocketAddr::V4.
impl From for SocketAddr
fn from(sock6: SocketAddrV6) -> SocketAddrConverts a
SocketAddrV6into aSocketAddr::V6.
impl FromStr for SocketAddr
fn from_str(s: &str) -> Result<SocketAddr, AddrParseError>
impl Hash for SocketAddr
fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)
impl Ord for SocketAddr
fn cmp(self: &Self, other: &SocketAddr) -> Ordering
impl PartialEq for SocketAddr
fn eq(self: &Self, other: &SocketAddr) -> bool
impl PartialOrd for SocketAddr
fn partial_cmp(self: &Self, other: &SocketAddr) -> Option<Ordering>
impl RefUnwindSafe for SocketAddr
impl Send for SocketAddr
impl StructuralPartialEq for SocketAddr
impl Sync for SocketAddr
impl Unpin for SocketAddr
impl UnsafeUnpin for SocketAddr
impl UnwindSafe for SocketAddr
impl<I: ~const Into<crate::net::IpAddr>> From for SocketAddr
fn from(pieces: (I, u16)) -> SocketAddrConverts a tuple struct (Into<
IpAddr>,u16) into aSocketAddr.This conversion creates a
SocketAddr::V4for anIpAddr::V4and creates aSocketAddr::V6for anIpAddr::V6.u16is treated as port of the newly createdSocketAddr.
impl<T> Any for SocketAddr
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for SocketAddr
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for SocketAddr
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for SocketAddr
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for SocketAddr
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for SocketAddr
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 SocketAddr
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for SocketAddr
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>