#[repr(C)]
pub union SockaddrStorage {
/* private fields */
}
Expand description
A container for any sockaddr type
Just like C’s sockaddr_storage
, this type is large enough to hold any type
of sockaddr. It can be used as an argument with functions like
bind
and getsockname
. Though it is
a union, it can be safely accessed through the as_*
methods.
§Example
let localhost = SockaddrIn::from_str("127.0.0.1:8081").unwrap();
let fd = socket(AddressFamily::Inet, SockType::Stream, SockFlag::empty(),
None).unwrap();
bind(fd, &localhost).expect("bind");
let ss: SockaddrStorage = getsockname(fd).expect("getsockname");
assert_eq!(&localhost, ss.as_sockaddr_in().unwrap());
Implementations§
Source§impl SockaddrStorage
impl SockaddrStorage
Sourcepub fn as_unix_addr(&self) -> Option<&UnixAddr>
pub fn as_unix_addr(&self) -> Option<&UnixAddr>
Downcast to an immutable [UnixAddr]
reference.
Sourcepub fn as_unix_addr_mut(&mut self) -> Option<&mut UnixAddr>
pub fn as_unix_addr_mut(&mut self) -> Option<&mut UnixAddr>
Downcast to a mutable [UnixAddr]
reference.
Sourcepub fn as_link_addr(&self) -> Option<&LinkAddr>
pub fn as_link_addr(&self) -> Option<&LinkAddr>
Safely and falliably downcast to an immutable reference
Sourcepub fn as_link_addr_mut(&mut self) -> Option<&mut LinkAddr>
pub fn as_link_addr_mut(&mut self) -> Option<&mut LinkAddr>
Safely and falliably downcast to a mutable reference
Sourcepub fn as_sockaddr_in(&self) -> Option<&SockaddrIn>
pub fn as_sockaddr_in(&self) -> Option<&SockaddrIn>
Safely and falliably downcast to an immutable reference
Sourcepub fn as_sockaddr_in_mut(&mut self) -> Option<&mut SockaddrIn>
pub fn as_sockaddr_in_mut(&mut self) -> Option<&mut SockaddrIn>
Safely and falliably downcast to a mutable reference
Sourcepub fn as_sockaddr_in6(&self) -> Option<&SockaddrIn6>
pub fn as_sockaddr_in6(&self) -> Option<&SockaddrIn6>
Safely and falliably downcast to an immutable reference
Sourcepub fn as_sockaddr_in6_mut(&mut self) -> Option<&mut SockaddrIn6>
pub fn as_sockaddr_in6_mut(&mut self) -> Option<&mut SockaddrIn6>
Safely and falliably downcast to a mutable reference
Trait Implementations§
Source§impl Clone for SockaddrStorage
impl Clone for SockaddrStorage
Source§fn clone(&self) -> SockaddrStorage
fn clone(&self) -> SockaddrStorage
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for SockaddrStorage
impl Debug for SockaddrStorage
Source§impl Display for SockaddrStorage
impl Display for SockaddrStorage
Source§impl From<SocketAddr> for SockaddrStorage
impl From<SocketAddr> for SockaddrStorage
Source§fn from(s: SocketAddr) -> Self
fn from(s: SocketAddr) -> Self
Converts to this type from the input type.
Source§impl From<SocketAddrV4> for SockaddrStorage
impl From<SocketAddrV4> for SockaddrStorage
Source§fn from(s: SocketAddrV4) -> Self
fn from(s: SocketAddrV4) -> Self
Converts to this type from the input type.
Source§impl From<SocketAddrV6> for SockaddrStorage
impl From<SocketAddrV6> for SockaddrStorage
Source§fn from(s: SocketAddrV6) -> Self
fn from(s: SocketAddrV6) -> Self
Converts to this type from the input type.
Source§impl Hash for SockaddrStorage
impl Hash for SockaddrStorage
Source§impl PartialEq for SockaddrStorage
impl PartialEq for SockaddrStorage
Source§impl SockaddrLike for SockaddrStorage
impl SockaddrLike for SockaddrStorage
Source§unsafe fn from_raw(addr: *const sockaddr, l: Option<socklen_t>) -> Option<Self>where
Self: Sized,
unsafe fn from_raw(addr: *const sockaddr, l: Option<socklen_t>) -> Option<Self>where
Self: Sized,
Unsafe constructor from a variable length source Read more
Source§fn len(&self) -> socklen_t
fn len(&self) -> socklen_t
Return the length of valid data in the sockaddr structure. Read more
impl Copy for SockaddrStorage
impl Eq for SockaddrStorage
Auto Trait Implementations§
impl Freeze for SockaddrStorage
impl RefUnwindSafe for SockaddrStorage
impl Send for SockaddrStorage
impl Sync for SockaddrStorage
impl Unpin for SockaddrStorage
impl UnwindSafe for SockaddrStorage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)