use std::collections::HashMap; use quick_xml::{events::attributes::Attribute, name::Namespace}; pub use xml_derive::XmlSerialize; use crate::XmlRootTag; pub trait XmlSerialize { fn serialize( &self, ns: Option, tag: Option<&[u8]>, namespaces: &HashMap, writer: &mut quick_xml::Writer, ) -> std::io::Result<()>; fn attributes<'a>(&self) -> Option>>>; } impl XmlSerialize for Option { fn serialize( &self, ns: Option, tag: Option<&[u8]>, namespaces: &HashMap, writer: &mut quick_xml::Writer, ) -> std::io::Result<()> { if let Some(some) = self { some.serialize(ns, tag, namespaces, writer) } else { Ok(()) } } #[allow(refining_impl_trait)] fn attributes<'a>(&self) -> Option>> { None } } pub trait XmlSerializeRoot { fn serialize_root( &self, writer: &mut quick_xml::Writer, ) -> std::io::Result<()>; } impl XmlSerializeRoot for T { fn serialize_root( &self, writer: &mut quick_xml::Writer, ) -> std::io::Result<()> { let namespaces = Self::root_ns_prefixes(); self.serialize(Self::root_ns(), Some(Self::root_tag()), &namespaces, writer) } }