use std::borrow::Cow;
use super::{percent::decode_percents_str, DBusAddr, Error, KeyValFmt, Result, TransportImpl};
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Launchd<'a> {
env: Cow<'a, str>,
}
impl<'a> Launchd<'a> {
pub fn env(&self) -> &str {
self.env.as_ref()
}
pub fn into_owned(self) -> Launchd<'static> {
Launchd {
env: self.env.into_owned().into(),
}
}
}
impl<'a> TransportImpl<'a> for Launchd<'a> {
fn for_address(s: &'a DBusAddr<'a>) -> Result<Self> {
for (k, v) in s.key_val_iter() {
match (k, v) {
("env", Some(v)) => {
return Ok(Launchd {
env: decode_percents_str(v)?,
});
}
_ => continue,
}
}
Err(Error::MissingKey("env".into()))
}
fn fmt_key_val<'s: 'b, 'b>(&'s self, kv: KeyValFmt<'b>) -> KeyValFmt<'b> {
kv.add("env", Some(self.env()))
}
}