#[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_alg_addr(&self) -> Option<&AlgAddr>
pub fn as_alg_addr(&self) -> Option<&AlgAddr>
Safely and falliably downcast to an immutable reference
sourcepub fn as_alg_addr_mut(&mut self) -> Option<&mut AlgAddr>
pub fn as_alg_addr_mut(&mut self) -> Option<&mut AlgAddr>
Safely and falliably downcast to a mutable reference
sourcepub fn as_netlink_addr(&self) -> Option<&NetlinkAddr>
pub fn as_netlink_addr(&self) -> Option<&NetlinkAddr>
Safely and falliably downcast to an immutable reference
sourcepub fn as_netlink_addr_mut(&mut self) -> Option<&mut NetlinkAddr>
pub fn as_netlink_addr_mut(&mut self) -> Option<&mut NetlinkAddr>
Safely and falliably downcast to a mutable reference
sourcepub fn as_vsock_addr(&self) -> Option<&VsockAddr>
pub fn as_vsock_addr(&self) -> Option<&VsockAddr>
Safely and falliably downcast to an immutable reference
sourcepub fn as_vsock_addr_mut(&mut self) -> Option<&mut VsockAddr>
pub fn as_vsock_addr_mut(&mut self) -> Option<&mut VsockAddr>
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 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
)