rama_unix/unix/
address.rs

1use crate::TokioSocketAddress;
2use std::path::Path;
3
4#[derive(Clone)]
5/// An address associated with a Unix socket.
6///
7/// This type is a thin wrapper around [`std::os::unix::net::SocketAddr`]. You
8/// can convert to and from the standard library `SocketAddr` type using the
9/// [`From`] trait. It is also just as easily convertabible to and from a tokio unix SocketAddr.
10pub struct UnixSocketAddress(pub(crate) std::os::unix::net::SocketAddr);
11
12impl UnixSocketAddress {
13    /// Returns `true` if the address is unnamed.
14    ///
15    /// Documentation reflected in [`SocketAddr`]
16    ///
17    /// [`SocketAddr`]: std::os::unix::net::SocketAddr
18    #[must_use]
19    pub fn is_unnamed(&self) -> bool {
20        self.0.is_unnamed()
21    }
22
23    /// Returns the contents of this address if it is a `pathname` address.
24    ///
25    /// Documentation reflected in [`SocketAddr`]
26    ///
27    /// [`SocketAddr`]: std::os::unix::net::SocketAddr
28    #[must_use]
29    pub fn as_pathname(&self) -> Option<&Path> {
30        self.0.as_pathname()
31    }
32}
33
34impl std::fmt::Debug for UnixSocketAddress {
35    fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36        self.0.fmt(fmt)
37    }
38}
39
40impl From<std::os::unix::net::SocketAddr> for UnixSocketAddress {
41    fn from(value: std::os::unix::net::SocketAddr) -> Self {
42        Self(value)
43    }
44}
45
46impl From<UnixSocketAddress> for std::os::unix::net::SocketAddr {
47    fn from(value: UnixSocketAddress) -> Self {
48        value.0
49    }
50}
51
52impl From<TokioSocketAddress> for UnixSocketAddress {
53    fn from(value: TokioSocketAddress) -> Self {
54        Self(value.into())
55    }
56}
57
58impl From<UnixSocketAddress> for TokioSocketAddress {
59    fn from(value: UnixSocketAddress) -> Self {
60        value.0.into()
61    }
62}