dbus_server_address_parser/encode/
address.rs

1use crate::Address;
2use std::fmt::{Display, Formatter, Result as FmtResult};
3
4impl Address {
5    /// Encode [server addresses] separated by `;`.
6    ///
7    /// [server address]: https://dbus.freedesktop.org/doc/dbus-specification.html#addresses
8    pub fn encode(addresses: &[Address]) -> String {
9        let mut iter = addresses.iter();
10        if let Some(address) = iter.next() {
11            let mut result = address.to_string();
12            for address in iter {
13                result.push(';');
14                result += &address.to_string();
15            }
16            result
17        } else {
18            String::new()
19        }
20    }
21}
22
23impl Display for Address {
24    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
25        match self {
26            Address::Unix(unix) => unix.fmt(f),
27            Address::Launchd(launchd) => launchd.fmt(f),
28            Address::Tcp(tcp) => tcp.fmt(f),
29            Address::NonceTcp(nonce_tcp) => nonce_tcp.fmt(f),
30            Address::Unixexec(unixexec) => unixexec.fmt(f),
31            Address::Systemd(systemd) => systemd.fmt(f),
32            Address::Autolaunch(autolaunch) => autolaunch.fmt(f),
33        }
34    }
35}