use darling::FromMeta; use proc_macro::TokenStream; use syn::{parse_macro_input, ItemImpl}; extern crate proc_macro; mod args { use darling::FromMeta; #[derive(FromMeta, Default)] #[darling(default)] pub struct Object {} } mod actions { use proc_macro::TokenStream; use syn::ItemImpl; use crate::{args, utils::GeneratorResult}; pub fn generate( object_args: &args::Object, item_impl: &mut ItemImpl, ) -> GeneratorResult { todo!() } } mod utils { pub type GeneratorResult = std::result::Result; } macro_rules! parse_nested_meta { ($ty:ty, $args:expr) => {{ let meta = match darling::ast::NestedMeta::parse_meta_list(proc_macro2::TokenStream::from( $args, )) { Ok(v) => v, Err(e) => { return TokenStream::from(darling::Error::from(e).write_errors()); } }; match <$ty>::from_list(&meta) { Ok(object_args) => object_args, Err(err) => return TokenStream::from(err.write_errors()), } }}; } #[proc_macro_attribute] #[allow(non_snake_case)] pub fn Actions(args: TokenStream, input: TokenStream) -> TokenStream { let object_args = parse_nested_meta!(args::Object, args); let mut item_impl = parse_macro_input!(input as ItemImpl); match actions::generate(&object_args, &mut item_impl) { Ok(expanded) => expanded, Err(err) => err.to_compile_error().into(), } }