tokio/net/unix/
socketaddr.rs

1use std::fmt;
2use 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#[derive(Clone)]
10pub struct SocketAddr(pub(super) std::os::unix::net::SocketAddr);
11
12impl SocketAddr {
13    /// Returns `true` if the address is unnamed.
14    ///
15    /// Documentation reflected in [`SocketAddr`]
16    ///
17    /// [`SocketAddr`]: std::os::unix::net::SocketAddr
18    pub fn is_unnamed(&self) -> bool {
19        self.0.is_unnamed()
20    }
21
22    /// Returns the contents of this address if it is a `pathname` address.
23    ///
24    /// Documentation reflected in [`SocketAddr`]
25    ///
26    /// [`SocketAddr`]: std::os::unix::net::SocketAddr
27    pub fn as_pathname(&self) -> Option<&Path> {
28        self.0.as_pathname()
29    }
30}
31
32impl fmt::Debug for SocketAddr {
33    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
34        self.0.fmt(fmt)
35    }
36}
37
38impl From<std::os::unix::net::SocketAddr> for SocketAddr {
39    fn from(value: std::os::unix::net::SocketAddr) -> Self {
40        SocketAddr(value)
41    }
42}
43
44impl From<SocketAddr> for std::os::unix::net::SocketAddr {
45    fn from(value: SocketAddr) -> Self {
46        value.0
47    }
48}