dbus_server_address_parser/
unix.rs

1use crate::Guid;
2
3/// This represents a DBus server address with the prefix [`unix:`].
4///
5/// [`unix:`]: https://dbus.freedesktop.org/doc/dbus-specification.html#transports-unix-domain-sockets-addresses
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct Unix {
8    pub r#type: UnixType,
9    /// The GUID of the Address.
10    pub guid: Option<Guid>,
11}
12
13impl Unix {
14    pub fn is_connectable(&self) -> bool {
15        self.r#type.is_connectable()
16    }
17
18    pub fn is_listenable(&self) -> bool {
19        self.r#type.is_listenable()
20    }
21}
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub enum UnixType {
25    /// Path of the unix domain socket.
26    Path(String),
27    /// Directory in which a socket file with a random file name starting with `dbus-` will be
28    /// created by the server.
29    Dir(String),
30    /// The same as `Dir`, except that on platforms with abstract sockets, the server may attempt
31    /// to create an abstract socket whose name starts with this directory instead of a path-based
32    /// socket.
33    Tmpdir(String),
34    /// Unique string in the abstract namespace, often syntactically resembling a path but
35    /// unconnected to the filesystem namespace.
36    Abstract(String),
37    /// `XDG_RUNTIME_DIR`
38    Runtime,
39}
40
41impl UnixType {
42    pub fn is_connectable(&self) -> bool {
43        match self {
44            UnixType::Path(_) => true,
45            UnixType::Dir(_) => false,
46            UnixType::Tmpdir(_) => false,
47            UnixType::Abstract(_) => true,
48            UnixType::Runtime => false,
49        }
50    }
51
52    pub fn is_listenable(&self) -> bool {
53        true
54    }
55}