xml: Add tag_name extractor

This commit is contained in:
Lennart
2024-12-23 11:57:01 +01:00
parent 67ab2ff62b
commit fa2851dc81
4 changed files with 31 additions and 5 deletions

View File

@@ -219,6 +219,24 @@ impl Field {
})
}
pub fn tagname_branch(&self) -> Option<proc_macro2::TokenStream> {
if self.attrs.xml_ty != FieldType::TagName {
return None;
}
let field_ident = self.field_ident();
let value = wrap_option_if_no_default(
quote! {
rustical_xml::Value::deserialize(&String::from_utf8_lossy(name.as_ref()))?
},
self.attrs.default.is_some(),
);
Some(quote! {
builder.#field_ident = #value;
})
}
pub fn tag_writer(&self) -> Option<proc_macro2::TokenStream> {
let field_ident = self.field_ident();
let field_name = self.xml_name();
@@ -235,6 +253,8 @@ impl Field {
// TODO: untag!
self.#field_ident.serialize(None, writer)?;
}),
// TODO: Think about what to do here
FieldType::TagName | FieldType::Namespace => None,
}
}
}