✨ Mark async main function with #[pagetop::main]
Also, use #[pagetop::test] for test functions. Add actix-web to Cargo.toml only when using Actix Web macros for service configuration.
This commit is contained in:
parent
4ce59d6520
commit
05304f116a
12 changed files with 58 additions and 21 deletions
|
|
@ -54,3 +54,43 @@ pub fn fn_builder(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||
};
|
||||
expanded.into()
|
||||
}
|
||||
|
||||
/// Marks async main function as the PageTop entry-point.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// #[pagetop::main]
|
||||
/// async fn main() {
|
||||
/// async { println!("Hello world"); }.await
|
||||
/// }
|
||||
/// ```
|
||||
#[proc_macro_attribute]
|
||||
pub fn main(_: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let mut output: TokenStream = (quote! {
|
||||
#[::pagetop::service::rt::main(system = "::pagetop::service::rt::System")]
|
||||
})
|
||||
.into();
|
||||
|
||||
output.extend(item);
|
||||
output
|
||||
}
|
||||
|
||||
/// Marks async test functions to use the PageTop entry-point.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// #[pagetop::test]
|
||||
/// async fn test() {
|
||||
/// assert_eq!(async { "Hello world" }.await, "Hello world");
|
||||
/// }
|
||||
/// ```
|
||||
#[proc_macro_attribute]
|
||||
pub fn test(_: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let mut output: TokenStream = (quote! {
|
||||
#[::pagetop::service::rt::test(system = "::pagetop::service::rt::System")]
|
||||
})
|
||||
.into();
|
||||
|
||||
output.extend(item);
|
||||
output
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue