use std::{collections::HashMap, convert::TryFrom};
use serde::{Deserialize, Serialize};
use super::super::{NmError, connection::DbusDictionary, convert::ToDbusValue};
#[derive(Debug, Clone, PartialEq, Default, Deserialize, Serialize)]
#[serde(try_from = "DbusDictionary")]
#[non_exhaustive]
pub struct NmSettingVeth {
pub peer: Option<String>,
_other: HashMap<String, zvariant::OwnedValue>,
}
impl TryFrom<DbusDictionary> for NmSettingVeth {
type Error = NmError;
fn try_from(mut v: DbusDictionary) -> Result<Self, Self::Error> {
Ok(Self {
peer: _from_map!(v, "peer", String::try_from)?,
_other: v,
})
}
}
impl ToDbusValue for NmSettingVeth {
fn to_value(&self) -> Result<HashMap<&str, zvariant::Value<'_>>, NmError> {
let mut ret = HashMap::new();
if let Some(v) = &self.peer {
ret.insert("peer", zvariant::Value::new(v.clone()));
}
ret.extend(self._other.iter().map(|(key, value)| {
(key.as_str(), zvariant::Value::from(value.clone()))
}));
Ok(ret)
}
}