mirror of
https://github.com/actix/actix-web.git
synced 2024-12-30 12:00:38 +00:00
Deduplicate rt::main macro logic (#2255)
This commit is contained in:
parent
2e1d761854
commit
e46cda5228
2 changed files with 4 additions and 21 deletions
|
@ -58,7 +58,7 @@ rustls = ["actix-http/rustls", "actix-tls/accept", "actix-tls/rustls"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-codec = "0.4.0"
|
actix-codec = "0.4.0"
|
||||||
actix-macros = "0.2.0"
|
actix-macros = "0.2.1"
|
||||||
actix-router = "0.2.7"
|
actix-router = "0.2.7"
|
||||||
actix-rt = "2.2"
|
actix-rt = "2.2"
|
||||||
actix-server = "2.0.0-beta.3"
|
actix-server = "2.0.0-beta.3"
|
||||||
|
|
|
@ -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(system = "::actix_web::rt::System")]
|
||||||
#vis #sig {
|
#input
|
||||||
actix_web::rt::System::new()
|
|
||||||
.block_on(async move { #body })
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue