xml: Implement XmlSerialize for enums

This commit is contained in:
Lennart
2024-12-27 13:53:30 +01:00
parent fc8d64220f
commit c787a6e8f3
4 changed files with 96 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
use quick_xml::events::BytesEnd;
use quick_xml::events::{BytesStart, Event};
use std::io::BufRead;
@@ -34,6 +35,27 @@ impl XmlDeserialize for () {
}
}
impl XmlSerialize for () {
fn serialize<W: std::io::Write>(
&self,
ns: Option<&[u8]>,
tag: Option<&[u8]>,
writer: &mut quick_xml::Writer<W>,
) -> std::io::Result<()> {
let tag_str = tag.map(String::from_utf8_lossy);
if let Some(tag) = &tag_str {
writer.write_event(Event::Empty(BytesStart::new(tag.clone())))?;
}
Ok(())
}
#[allow(refining_impl_trait)]
fn attributes<'a>(&self) -> Vec<quick_xml::events::attributes::Attribute<'a>> {
vec![]
}
}
// TODO: actually implement
#[derive(Debug, Clone, PartialEq)]
pub struct Unparsed(BytesStart<'static>);