epp_client/
xml.rs

1//! Types to use in serialization to and deserialization from EPP XML
2
3use serde::{de::DeserializeOwned, Serialize};
4
5use crate::error::Error;
6
7pub const EPP_XML_HEADER: &str = r#"<?xml version="1.0" encoding="UTF-8" standalone="no"?>"#;
8
9pub(crate) fn serialize(doc: &impl Serialize) -> Result<String, Error> {
10    Ok(format!(
11        "{}\r\n{}",
12        EPP_XML_HEADER,
13        quick_xml::se::to_string(doc).map_err(|e| Error::Xml(e.into()))?
14    ))
15}
16
17pub(crate) fn deserialize<T: DeserializeOwned>(xml: &str) -> Result<T, Error> {
18    quick_xml::de::from_str(xml).map_err(|e| Error::Xml(e.into()))
19}