diff --git a/actix-web-codegen/src/lib.rs b/actix-web-codegen/src/lib.rs index 336345014..d5a2e3fe7 100644 --- a/actix-web-codegen/src/lib.rs +++ b/actix-web-codegen/src/lib.rs @@ -7,16 +7,6 @@ //! explicit imports. Check the latest [actix-web attributes docs] to see which macros //! are re-exported. //! -//! # Runtime Setup -//! Used for setting up the actix async runtime. See [macro@main] macro docs. -//! -//! ``` -//! #[actix_web_codegen::main] // or `#[actix_web::main]` in Actix Web apps -//! async fn main() { -//! async { println!("Hello world"); }.await -//! } -//! ``` -//! //! # Single Method Handler //! There is a macro to set up a handler for each of the most common HTTP methods that also define //! additional guards and route-specific middleware. @@ -155,43 +145,3 @@ method_macro! { Trace, trace, Patch, patch, } - -/// Marks async main function as the actix system entry-point. -/// -/// # Actix Web Re-export -/// This macro can be applied with `#[actix_web::main]` when used in Actix Web applications. -/// -/// # Examples -/// ``` -/// #[actix_web_codegen::main] -/// async fn main() { -/// async { println!("Hello world"); }.await -/// } -/// ``` -#[proc_macro_attribute] -pub fn main(_: TokenStream, item: TokenStream) -> TokenStream { - use quote::quote; - - 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! { - #(#attrs)* - #vis #sig { - actix_web::rt::System::new() - .block_on(async move { #body }) - } - }) - .into() -} diff --git a/src/lib.rs b/src/lib.rs index cf1bfa590..9397af500 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,6 +100,7 @@ pub use actix_http::Response as BaseHttpResponse; pub use actix_http::{body, Error, HttpMessage, ResponseError, Result}; #[doc(inline)] pub use actix_rt as rt; +pub use actix_rt::main; pub use actix_web_codegen::*; #[cfg(feature = "cookies")] pub use cookie;