mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 08:12:24 +00:00
xml: Add namespace deserialisation
This commit is contained in:
@@ -246,6 +246,25 @@ impl Field {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn namespace_branch(&self) -> Option<proc_macro2::TokenStream> {
|
||||
if self.attrs.xml_ty != FieldType::Namespace {
|
||||
return None;
|
||||
}
|
||||
let builder_field_ident = self.builder_field_ident();
|
||||
|
||||
let value = quote! {
|
||||
if let ::quick_xml::name::ResolveResult::Bound(ns) = &ns {
|
||||
Some(rustical_xml::ValueDeserialize::deserialize(&String::from_utf8_lossy(ns.0.as_ref()))?)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
Some(quote! {
|
||||
builder.#builder_field_ident = #value;
|
||||
})
|
||||
}
|
||||
|
||||
pub fn tagname_branch(&self) -> Option<proc_macro2::TokenStream> {
|
||||
if self.attrs.xml_ty != FieldType::TagName {
|
||||
return None;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::attrs::{FieldType, StructAttrs};
|
||||
use crate::Field;
|
||||
use crate::attrs::{FieldType, StructAttrs};
|
||||
use core::panic;
|
||||
use darling::FromDeriveInput;
|
||||
use quote::quote;
|
||||
@@ -115,6 +115,7 @@ impl NamedStruct {
|
||||
self.fields.iter().filter_map(Field::text_branch).collect();
|
||||
let attr_field_branches = self.fields.iter().filter_map(Field::attr_branch);
|
||||
let tagname_field_branches = self.fields.iter().filter_map(Field::tagname_branch);
|
||||
let namespace_field_branches = self.fields.iter().filter_map(Field::namespace_branch);
|
||||
|
||||
let builder_field_builds = self.fields.iter().map(Field::builder_field_build);
|
||||
|
||||
@@ -144,6 +145,7 @@ impl NamedStruct {
|
||||
|
||||
let (ns, name) = reader.resolve_element(start.name());
|
||||
#(#tagname_field_branches);*
|
||||
#(#namespace_field_branches);*
|
||||
|
||||
for attr in start.attributes() {
|
||||
let attr = attr?;
|
||||
|
||||
Reference in New Issue
Block a user