mirror of https://github.com/fafhrd91/actix-web
deduplicate rt::main macro logic
This commit is contained in:
parent
0bb035cfa7
commit
f071f85883
|
@ -171,27 +171,10 @@ method_macro! {
|
||||||
#[proc_macro_attribute]
|
#[proc_macro_attribute]
|
||||||
pub fn main(_: TokenStream, item: TokenStream) -> TokenStream {
|
pub fn main(_: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
let input = syn::parse_macro_input!(item as syn::ItemFn);
|
||||||
let mut input = syn::parse_macro_input!(item as syn::ItemFn);
|
|
||||||
let attrs = &input.attrs;
|
|
||||||
let vis = &input.vis;
|
|
||||||
let sig = &mut input.sig;
|
|
||||||
let body = &input.block;
|
|
||||||
|
|
||||||
if sig.asyncness.is_none() {
|
|
||||||
return syn::Error::new_spanned(sig.fn_token, "only async fn is supported")
|
|
||||||
.to_compile_error()
|
|
||||||
.into();
|
|
||||||
}
|
|
||||||
|
|
||||||
sig.asyncness = None;
|
|
||||||
|
|
||||||
(quote! {
|
(quote! {
|
||||||
#(#attrs)*
|
#[actix_web::rt::main]
|
||||||
#vis #sig {
|
#input
|
||||||
actix_web::rt::System::new()
|
|
||||||
.block_on(async move { #body })
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue