Struct os_socketaddr::OsSocketAddr
source · [−]pub struct OsSocketAddr { /* private fields */ }Expand description
A type for handling platform-native socket addresses (struct sockaddr)
This type has a buffer big enough to hold a [libc::sockaddr_in] or [libc::sockaddr_in6] struct. Its content can be arbitrary written using .as_mut() or .as_mut_ptr().
It also provides the conversion functions from/into SocketAddr.
See crate level documentation.
Implementations
sourceimpl OsSocketAddr
impl OsSocketAddr
sourcepub unsafe fn from_raw_parts(ptr: *const u8, len: usize) -> Self
pub unsafe fn from_raw_parts(ptr: *const u8, len: usize) -> Self
Create a new socket address from a raw slice
Panics
Panics if len is bigger that the size of sockaddr_in6
sourcepub fn from(addr: SocketAddr) -> Self
pub fn from(addr: SocketAddr) -> Self
Create a new socket address from a SocketAddr object
sourcepub fn into_addr(self) -> Option<SocketAddr>
pub fn into_addr(self) -> Option<SocketAddr>
Attempt to convert the internal buffer into a SocketAddr object
The internal buffer is assumed to be a sockaddr.
If the value of .sa_family resolves to AF_INET or AF_INET6 then the buffer is
converted into SocketAddr, otherwise the function returns None.
sourcepub fn len(&self) -> socklen_t
pub fn len(&self) -> socklen_t
Return the length of the address
The result depends on the value of .sa_family in the internal buffer:
AF_INET-> the size of sockaddr_inAF_INET6-> the size of sockaddr_in6- other -> 0
sourcepub fn as_mut_ptr(&mut self) -> *mut sockaddr
pub fn as_mut_ptr(&mut self) -> *mut sockaddr
Get a mutable pointer to the internal buffer
Trait Implementations
sourceimpl Clone for OsSocketAddr
impl Clone for OsSocketAddr
sourcefn clone(&self) -> OsSocketAddr
fn clone(&self) -> OsSocketAddr
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for OsSocketAddr
impl Debug for OsSocketAddr
sourceimpl From<Option<SocketAddr>> for OsSocketAddr
impl From<Option<SocketAddr>> for OsSocketAddr
sourcefn from(addr: Option<SocketAddr>) -> Self
fn from(addr: Option<SocketAddr>) -> Self
Converts to this type from the input type.
sourceimpl From<SocketAddr> for OsSocketAddr
impl From<SocketAddr> for OsSocketAddr
sourcefn from(addr: SocketAddr) -> Self
fn from(addr: SocketAddr) -> Self
Converts to this type from the input type.
sourceimpl Into<Option<SocketAddr>> for OsSocketAddr
impl Into<Option<SocketAddr>> for OsSocketAddr
sourcefn into(self) -> Option<SocketAddr>
fn into(self) -> Option<SocketAddr>
Attempt to convert the internal buffer into a SocketAddr object
The internal buffer is assumed to be a sockaddr.
If the value of .sa_family resolves to AF_INET or AF_INET6 then the buffer is
converted into SocketAddr, otherwise the function returns None.
sourceimpl TryInto<SocketAddr> for OsSocketAddr
impl TryInto<SocketAddr> for OsSocketAddr
sourcefn try_into(self) -> Result<SocketAddr, BadFamilyError>
fn try_into(self) -> Result<SocketAddr, BadFamilyError>
Attempt to convert the internal buffer into a SocketAddr object
The internal buffer is assumed to be a sockaddr.
If the value of .sa_family resolves to AF_INET or AF_INET6 then the buffer is
converted into SocketAddr, otherwise the function returns an error.
type Error = BadFamilyError
type Error = BadFamilyError
The type returned in the event of a conversion error.
impl Copy for OsSocketAddr
Auto Trait Implementations
impl RefUnwindSafe for OsSocketAddr
impl Send for OsSocketAddr
impl Sync for OsSocketAddr
impl Unpin for OsSocketAddr
impl UnwindSafe for OsSocketAddr
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more