use yaserde_derive::{YaDeserialize, YaSerialize}; use yaserde::MaybeString; use super::opnsense::{NumberOption, Range, StaticMap}; // #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] // #[yaserde(rename = "dhcpd")] // pub struct Dhcpd { // #[yaserde(rename = "lan")] // pub lan: DhcpInterface, // } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct DhcpInterface { pub enable: Option, pub gateway: Option, pub domain: Option, pub netboot: Option, pub nextserver: Option, #[yaserde(rename = "ddnsdomainalgorithm")] pub ddns_domain_algorithm: Option, #[yaserde(rename = "numberoptions")] pub number_options: Vec, #[yaserde(rename = "range")] pub range: Range, pub winsserver: Option, pub dnsserver: Option, pub ntpserver: Option, #[yaserde(rename = "staticmap")] pub staticmaps: Vec, pub pool: Option, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct DhcpRange { #[yaserde(rename = "from")] pub from: String, #[yaserde(rename = "to")] pub to: String, } #[cfg(test)] mod test { use crate::xml_utils::to_xml_str; use pretty_assertions::assert_eq; #[test] fn dhcpd_should_deserialize_serialize_identical() { let dhcpd: Dhcpd = yaserde::de::from_str(SERIALIZED_DHCPD).expect("Deserialize Dhcpd failed"); assert_eq!( to_xml_str(&dhcpd).expect("Serialize Dhcpd failed"), SERIALIZED_DHCPD ); } const SERIALIZED_DHCPD: &str = " 1 192.168.20.1 somedomain.yourlocal.mcd hmac-md5 192.168.20.50 192.168.20.200 192.168.20.1 55:55:55:55:55:1c 192.168.20.160 somehost983 someservire8 55:55:55:55:55:1c 192.168.20.155 somehost893 55:55:55:55:55:1c 192.168.20.165 somehost893 55:55:55:55:55:1c 192.168.20.50 hostswitch2 switch-2 (bottom) \n"; }