use proc_macro::TokenStream;
use quote::quote;
use syn::ItemFn;
use syn::parse_macro_input;
use syn::spanned::Spanned;
use crate::FnInfo;
extern crate proc_macro;
pub fn command_impl(_args: TokenStream, input: TokenStream) -> TokenStream {
let func = parse_macro_input!(input as ItemFn);
{
match crate::rules::rule_check(_args.clone(), &func) {
Ok(_) => {}
Err(e) => return e.to_compile_error().into(),
};
}
let fn_info = match FnInfo::new(_args, &func) {
Ok(info) => info,
Err(e) => return e.into_compile_error().into(),
};
{
::once_cell::sync::Lazy::force(&crate::data::COMMANDS);
let re = crate::data::insert(fn_info.clone(), func.span());
if let Err(e) = re {
return e.into_compile_error().into();
}
}
let trait_bound_check_code = fn_info.gen_trait_bound_check();
let result = syn::parse_str::<syn::ItemConst>(&trait_bound_check_code);
match result {
Ok(trait_bound_check_ast) => {
return TokenStream::from(quote!(
#trait_bound_check_ast
#func
));
}
Err(_) => {
return TokenStream::from(quote!(
#func
));
}
}
}