xml: Some restructuring

This commit is contained in:
Lennart
2025-01-15 18:24:23 +01:00
parent d74f0ba660
commit d5c66ed233
9 changed files with 128 additions and 121 deletions

View File

@@ -28,7 +28,8 @@ pub struct VariantAttrs {
#[darling(attributes(xml))]
pub struct EnumAttrs {
#[darling(flatten)]
pub container: ContainerAttrs,
// TODO: implement ns_strict
pub _container: ContainerAttrs,
pub untagged: Flag,
}

View File

@@ -0,0 +1,16 @@
pub(crate) fn get_generic_type(ty: &syn::Type) -> Option<&syn::Type> {
if let syn::Type::Path(syn::TypePath { path, .. }) = ty {
if let Some(seg) = path.segments.last() {
if let syn::PathArguments::AngleBracketed(syn::AngleBracketedGenericArguments {
args,
..
}) = &seg.arguments
{
if let Some(syn::GenericArgument::Type(t)) = &args.first() {
return Some(t);
}
}
}
}
None
}

View File

@@ -324,7 +324,7 @@ impl Field {
(FieldType::Untagged, false) => Some(quote! {
#serializer(&self.#target_field_index, None, None, namespaces, writer)?;
}),
// TODO: Think about what to do here
// We ignore this :)
(FieldType::TagName | FieldType::Namespace, _) => None,
}
}

View File

@@ -2,33 +2,18 @@ use core::panic;
use syn::{parse_macro_input, DeriveInput};
pub(crate) mod attrs;
mod common;
mod field;
mod variant;
mod xml_enum;
mod xml_struct;
pub(crate) use common::*;
pub(crate) use field::Field;
pub(crate) use variant::Variant;
pub(crate) use xml_enum::Enum;
pub(crate) use xml_struct::NamedStruct;
pub(crate) fn get_generic_type(ty: &syn::Type) -> Option<&syn::Type> {
if let syn::Type::Path(syn::TypePath { path, .. }) = ty {
if let Some(seg) = path.segments.last() {
if let syn::PathArguments::AngleBracketed(syn::AngleBracketedGenericArguments {
args,
..
}) = &seg.arguments
{
if let Some(syn::GenericArgument::Type(t)) = &args.first() {
return Some(t);
}
}
}
}
None
}
#[proc_macro_derive(XmlDeserialize, attributes(xml))]
pub fn derive_xml_deserialize(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = parse_macro_input!(input as DeriveInput);