diff --git a/instant-xml-macros/src/lib.rs b/instant-xml-macros/src/lib.rs index b5380a1..3768d03 100644 --- a/instant-xml-macros/src/lib.rs +++ b/instant-xml-macros/src/lib.rs @@ -5,34 +5,34 @@ use quote::quote; use syn::{parse_macro_input, DeriveInput, Lit, Meta, NestedMeta}; fn retrieve_default_namespace(input: &DeriveInput) -> Option { - if let NestedMeta::Meta(Meta::List(list)) = get_meta_items(&input.attrs).first()? { + for attr in &input.attrs { + if !attr.path.is_ident(XML) { + continue; + } + + let nested = match attr.parse_meta() { + Ok(Meta::List(meta)) => meta.nested, + Ok(_) => todo!(), + _ => todo!(), + }; + + let list = match nested.first() { + Some(NestedMeta::Meta(Meta::List(list))) => list, + _ => todo!(), + }; + if list.path.get_ident()? == "namespace" { if let NestedMeta::Lit(Lit::Str(v)) = list.nested.first()? { return Some(v.value()); } } } + None } const XML: &str = "xml"; -pub(crate) fn get_meta_items(attrs: &[syn::Attribute]) -> Vec { - let mut out = Vec::new(); - for attr in attrs { - if !attr.path.is_ident(XML) { - continue; - } - - match attr.parse_meta() { - Ok(Meta::List(meta)) => out.extend(meta.nested.into_iter()), - Ok(_) => todo!(), - _ => todo!(), - } - } - out -} - #[proc_macro_derive(ToXml, attributes(xml))] pub fn to_xml(input: TokenStream) -> TokenStream { let ast = parse_macro_input!(input as syn::DeriveInput);