1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use quick_xml::de::from_str;
use quick_xml::se;
use serde::{de::DeserializeOwned, Serialize};
use std::{error::Error, fmt::Debug};
use crate::epp::object::{ElementName, EppObject};
use crate::epp::xml::{EppXml, EPP_XML_HEADER};
use crate::error;
impl<T: Serialize + DeserializeOwned + ElementName + Debug> EppXml for EppObject<T> {
type Output = EppObject<T>;
fn serialize(&self) -> Result<String, Box<dyn Error>> {
let epp_xml = format!("{}\r\n{}", EPP_XML_HEADER, se::to_string(self)?);
Ok(epp_xml)
}
fn deserialize(epp_xml: &str) -> Result<Self::Output, error::Error> {
let object: Self::Output = match from_str(epp_xml) {
Ok(v) => v,
Err(e) => {
return Err(error::Error::EppDeserializationError(
format!("epp-client Deserialization Error: {}", e).to_string(),
))
}
};
Ok(object)
}
}