pub struct SockAddrStorage(pub SOCKADDR_STORAGE);
Expand description

The SockAddrStorage struct represents a socket address for IPv4 or IPv6 addresses. It can be created from various Windows socket address types and can be converted to a std::net::SocketAddr.

Tuple Fields§

§0: SOCKADDR_STORAGE

Implementations§

source§

impl SockAddrStorage

source

pub fn new() -> Self

Constructs a new SockAddrStorage with all fields set to zero.

source

pub fn from_ip_string(ip_address: &str) -> Result<Self, AddrParseError>

Constructs a new SockAddrStorage instance from a string representation of an IPv4 or IPv6 address.

Arguments
  • ip_address - A string representation of an IPv4 or IPv6 address.
Returns

A Result containing a new SockAddrStorage instance, or an error if the input string is not a valid IP address.

source

pub fn from_sockaddr(address: SOCKADDR) -> Self

Constructs a new SockAddrStorage from a SOCKADDR struct.

Safety

This function uses MaybeUninit to safely create an uninitialized SOCKADDR_STORAGE instance, and then it copies the SOCKADDR contents into the SOCKADDR_STORAGE without overlapping. Before constructing the SockAddrStorage, it ensures that the contents are valid using the assume_init() method.

source

pub fn from_sockaddr_in(address: SOCKADDR_IN) -> Self

Constructs a new SockAddrStorage from a SOCKADDR_IN struct.

Safety

This function uses MaybeUninit to safely create an uninitialized SOCKADDR_STORAGE instance, and then it copies the SOCKADDR_IN contents into the SOCKADDR_STORAGE without overlapping. Before constructing the SockAddrStorage, it ensures that the contents are valid using the assume_init() method.

source

pub fn from_sockaddr_in6(address: SOCKADDR_IN6) -> Self

Constructs a new SockAddrStorage from a SOCKADDR_IN6 struct.

Safety

This function uses MaybeUninit to safely create an uninitialized SOCKADDR_STORAGE instance, and then it copies the SOCKADDR_IN6 contents into the SOCKADDR_STORAGE without overlapping. Before constructing the SockAddrStorage, it ensures that the contents are valid using the assume_init() method.

source

pub fn from_ipv4_addr(address: Ipv4Addr) -> Self

Constructs a new SockAddrStorage from an Ipv4Addr object.

source

pub fn from_ipv6_addr(address: Ipv6Addr) -> Self

Constructs a new SockAddrStorage from an Ipv6Addr object.

source

pub fn to_socket_addr(&self) -> Option<SocketAddr>

Converts the SockAddrStorage to a std::net::SocketAddr if it contains a valid IPv4 or IPv6 address.

source

pub fn to_string(&self) -> Option<String>

Converts the SockAddrStorage to a String representation of the IP address and port.

source

pub fn to_wide_string(&self) -> Option<String>

Converts the SockAddrStorage to a wide String representation of the IP address and port.

Trait Implementations§

source§

impl Clone for SockAddrStorage

source§

fn clone(&self) -> SockAddrStorage

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for SockAddrStorage

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for SockAddrStorage

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl From<SockAddrStorage> for IpAddr

source§

fn from(ip_address_info: SockAddrStorage) -> Self

Converts to this type from the input type.
source§

impl PartialEq<SockAddrStorage> for SockAddrStorage

source§

fn eq(&self, other: &SockAddrStorage) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for SockAddrStorage

source§

impl Eq for SockAddrStorage

source§

impl StructuralEq for SockAddrStorage

source§

impl StructuralPartialEq for SockAddrStorage

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.