1 use std::fmt; 2 use std::path::Path; 3 4 /// An address associated with a Tokio Unix socket. 5 /// 6 /// This type is a thin wrapper around [`std::os::unix::net::SocketAddr`]. You 7 /// can convert to and from the standard library `SocketAddr` type using the 8 /// [`From`] trait. 9 pub struct SocketAddr(pub(super) std::os::unix::net::SocketAddr); 10 11 impl SocketAddr { 12 /// Returns `true` if the address is unnamed. 13 /// 14 /// Documentation reflected in [`SocketAddr`] 15 /// 16 /// [`SocketAddr`]: std::os::unix::net::SocketAddr is_unnamed(&self) -> bool17 pub fn is_unnamed(&self) -> bool { 18 self.0.is_unnamed() 19 } 20 21 /// Returns the contents of this address if it is a `pathname` address. 22 /// 23 /// Documentation reflected in [`SocketAddr`] 24 /// 25 /// [`SocketAddr`]: std::os::unix::net::SocketAddr as_pathname(&self) -> Option<&Path>26 pub fn as_pathname(&self) -> Option<&Path> { 27 self.0.as_pathname() 28 } 29 } 30 31 impl fmt::Debug for SocketAddr { fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result32 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { 33 self.0.fmt(fmt) 34 } 35 } 36 37 impl From<std::os::unix::net::SocketAddr> for SocketAddr { from(value: std::os::unix::net::SocketAddr) -> Self38 fn from(value: std::os::unix::net::SocketAddr) -> Self { 39 SocketAddr(value) 40 } 41 } 42 43 impl From<SocketAddr> for std::os::unix::net::SocketAddr { from(value: SocketAddr) -> Self44 fn from(value: SocketAddr) -> Self { 45 value.0 46 } 47 } 48