Struct SocketAddr
pub struct SocketAddr { pub(in ::os::unix::net) addr: sockaddr_un, pub(in ::os::unix::net) len: socklen_t }
An address associated with a Unix socket.
Examples
use UnixListener;
let socket = match bind ;
let addr = socket.local_addr.expect;
Fields
addr: sockaddr_unlen: socklen_t
Implementations
impl SocketAddr
fn new<F>(f: F) -> Result<SocketAddr> where F: FnOnce(*mut sockaddr, *mut socklen_t) -> c_int,fn from_parts(addr: sockaddr_un, len: socklen_t) -> Result<SocketAddr>fn from_pathname<P>(path: P) -> Result<SocketAddr> where P: AsRef<Path>,Constructs a
SockAddrwith the familyAF_UNIXand the provided path.Errors
Returns an error if the path is longer than
SUN_LENor if it contains NULL bytes.Examples
use SocketAddr; use Path; #Creating a
SocketAddrwith a NULL byte results in an error.use SocketAddr; assert!;fn is_unnamed(&self) -> boolReturns
trueif the address is unnamed.Examples
A named address:
use std::os::unix::net::UnixListener; fn main() -> std::io::Result<()> { let socket = UnixListener::bind("/tmp/sock")?; let addr = socket.local_addr().expect("Couldn't get local address"); assert_eq!(addr.is_unnamed(), false); Ok(()) }An unnamed address:
use UnixDatagram;fn as_pathname(&self) -> Option<&Path>Returns the contents of this address if it is a
pathnameaddress.Examples
With a pathname:
use std::os::unix::net::UnixListener; use std::path::Path; fn main() -> std::io::Result<()> { let socket = UnixListener::bind("/tmp/sock")?; let addr = socket.local_addr().expect("Couldn't get local address"); assert_eq!(addr.as_pathname(), Some(Path::new("/tmp/sock"))); Ok(()) }Without a pathname:
use UnixDatagram;fn address(&self) -> AddressKind<'_>
Trait Implementations
impl Clone for SocketAddr
fn clone(&self) -> SocketAddr
impl Debug for SocketAddr
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result
impl SocketAddrExt for SocketAddr
fn as_abstract_name(&self) -> Option<&[u8]>fn from_abstract_name<N>(name: N) -> Result<Self> where N: AsRef<[u8]>,
Auto Trait Implementations
impl Freeze for SocketAddr
impl RefUnwindSafe for SocketAddr
impl Send for SocketAddr
impl Sync for SocketAddr
impl Unpin for SocketAddr
impl UnsafeUnpin for SocketAddr
impl UnwindSafe for SocketAddr
Blanket Implementations
impl<T> Any for SocketAddr
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for SocketAddr
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for SocketAddr
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for SocketAddr
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for SocketAddr
fn from(t: T) -> TReturns the argument unchanged.
impl<T> SizeHint for SocketAddr
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for SocketAddr
impl<T> ToOwned for SocketAddr
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for SocketAddr
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for SocketAddr
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for SocketAddr
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>