Inline get_meta_items()

This commit is contained in:
Dirkjan Ochtman 2022-06-13 11:34:57 +02:00
parent df244e89b6
commit 49212976a2
1 changed files with 17 additions and 17 deletions

View File

@ -5,34 +5,34 @@ use quote::quote;
use syn::{parse_macro_input, DeriveInput, Lit, Meta, NestedMeta};
fn retrieve_default_namespace(input: &DeriveInput) -> Option<String> {
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<NestedMeta> {
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);