mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-27 00:00:12 +02:00
macros: re-export main macro from tokio (#1198)
Includes minor fixes and a very basic example. Fixes #1183
This commit is contained in:
@@ -17,9 +17,11 @@ use syn::spanned::Spanned;
|
||||
/// ```
|
||||
/// #[tokio::main]
|
||||
/// async fn main() {
|
||||
/// println!("Hello world");
|
||||
/// println!("Hello from Tokio!");
|
||||
/// }
|
||||
/// ```
|
||||
#[proc_macro_attribute]
|
||||
#[cfg(not(test))] // Work around for rust-lang/rust#62127
|
||||
pub fn main(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let input = syn::parse_macro_input!(item as syn::ItemFn);
|
||||
|
||||
@@ -38,7 +40,7 @@ pub fn main(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let result = quote! {
|
||||
fn #name() #ret {
|
||||
let mut rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on_async(async { #body })
|
||||
rt.block_on(async { #body })
|
||||
}
|
||||
};
|
||||
|
||||
@@ -49,7 +51,7 @@ pub fn main(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// #[tokio::test]
|
||||
/// async fn my_test() {
|
||||
/// assert!(true);
|
||||
|
||||
Reference in New Issue
Block a user