mirror of https://github.com/fafhrd91/actix-net
Macro improvements.
This commit is contained in:
parent
35218a4df1
commit
d7800612a5
|
@ -18,24 +18,23 @@ use quote::quote;
|
||||||
#[cfg(not(test))] // Work around for rust-lang/rust#62127
|
#[cfg(not(test))] // Work around for rust-lang/rust#62127
|
||||||
pub fn main(_: TokenStream, item: TokenStream) -> TokenStream {
|
pub fn main(_: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
let input = syn::parse_macro_input!(item as syn::ItemFn);
|
let input = syn::parse_macro_input!(item as syn::ItemFn);
|
||||||
|
|
||||||
let ret = &input.sig.output;
|
|
||||||
let name = &input.sig.ident;
|
|
||||||
let inputs = &input.sig.inputs;
|
|
||||||
let body = &input.block;
|
|
||||||
let attrs = &input.attrs;
|
let attrs = &input.attrs;
|
||||||
|
let vis = &input.vis;
|
||||||
|
let sig = &input.sig;
|
||||||
|
let body = &input.block;
|
||||||
|
let name = &sig.ident;
|
||||||
|
|
||||||
if input.sig.asyncness.is_none() {
|
if sig.asyncness.is_none() {
|
||||||
return syn::Error::new_spanned(input.sig.fn_token, "only async fn is supported")
|
return syn::Error::new_spanned(sig.fn_token, "only async fn is supported")
|
||||||
.to_compile_error()
|
.to_compile_error()
|
||||||
.into();
|
.into();
|
||||||
}
|
}
|
||||||
|
|
||||||
(quote! {
|
(quote! {
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
fn #name(#inputs) #ret {
|
#vis #sig {
|
||||||
actix_rt::System::new("main")
|
actix_rt::System::new(stringify!(#name))
|
||||||
.block_on(async { #body })
|
.block_on(async move { #body })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.into()
|
.into()
|
||||||
|
|
Loading…
Reference in New Issue