mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 02:22:21 +00:00
xml: Create empty tags for empty fields
This commit is contained in:
@@ -221,6 +221,8 @@ impl NamedStruct {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let is_empty = tag_writers.len() == 0;
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
impl #impl_generics ::rustical_xml::XmlSerialize for #ident #type_generics #where_clause {
|
impl #impl_generics ::rustical_xml::XmlSerialize for #ident #type_generics #where_clause {
|
||||||
fn serialize<W: ::std::io::Write>(
|
fn serialize<W: ::std::io::Write>(
|
||||||
@@ -240,11 +242,17 @@ impl NamedStruct {
|
|||||||
bytes_start.extend_attributes(attrs);
|
bytes_start.extend_attributes(attrs);
|
||||||
}
|
}
|
||||||
#(#untagged_attributes);*
|
#(#untagged_attributes);*
|
||||||
writer.write_event(Event::Start(bytes_start))?;
|
if #is_empty {
|
||||||
|
writer.write_event(Event::Empty(bytes_start))?;
|
||||||
|
} else {
|
||||||
|
writer.write_event(Event::Start(bytes_start))?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#(#tag_writers);*
|
if !#is_empty {
|
||||||
if let Some(tag) = &tag_str {
|
#(#tag_writers);*
|
||||||
writer.write_event(Event::End(BytesEnd::new(tag.to_owned())))?;
|
if let Some(tag) = &tag_str {
|
||||||
|
writer.write_event(Event::End(BytesEnd::new(tag.to_owned())))?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user