mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-04 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:
+1
-1
@@ -9,7 +9,7 @@ members = [
|
|||||||
# "tokio-fs",
|
# "tokio-fs",
|
||||||
"tokio-futures",
|
"tokio-futures",
|
||||||
"tokio-io",
|
"tokio-io",
|
||||||
# "tokio-macros",
|
"tokio-macros",
|
||||||
"tokio-reactor",
|
"tokio-reactor",
|
||||||
# "tokio-signal",
|
# "tokio-signal",
|
||||||
"tokio-sync",
|
"tokio-sync",
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ jobs:
|
|||||||
- tokio-current-thread
|
- tokio-current-thread
|
||||||
- tokio-executor
|
- tokio-executor
|
||||||
- tokio-io
|
- tokio-io
|
||||||
|
- tokio-macros
|
||||||
- tokio-sync
|
- tokio-sync
|
||||||
# - tokio-threadpool
|
# - tokio-threadpool
|
||||||
# - tokio-timer
|
# - tokio-timer
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ jobs:
|
|||||||
- template: azure-patch-crates.yml
|
- template: azure-patch-crates.yml
|
||||||
|
|
||||||
- ${{ each crate in parameters.crates }}:
|
- ${{ each crate in parameters.crates }}:
|
||||||
- script: cargo test --lib && cargo test --tests
|
- script: cargo test --lib && cargo test --tests && cargo test --examples
|
||||||
env:
|
env:
|
||||||
LOOM_MAX_DURATION: 10
|
LOOM_MAX_DURATION: 10
|
||||||
CI: 'True'
|
CI: 'True'
|
||||||
|
|||||||
@@ -17,9 +17,11 @@ use syn::spanned::Spanned;
|
|||||||
/// ```
|
/// ```
|
||||||
/// #[tokio::main]
|
/// #[tokio::main]
|
||||||
/// async fn main() {
|
/// async fn main() {
|
||||||
/// println!("Hello world");
|
/// println!("Hello from Tokio!");
|
||||||
/// }
|
/// }
|
||||||
|
/// ```
|
||||||
#[proc_macro_attribute]
|
#[proc_macro_attribute]
|
||||||
|
#[cfg(not(test))] // Work around for rust-lang/rust#62127
|
||||||
pub fn main(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
pub fn main(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
let input = syn::parse_macro_input!(item as syn::ItemFn);
|
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! {
|
let result = quote! {
|
||||||
fn #name() #ret {
|
fn #name() #ret {
|
||||||
let mut rt = tokio::runtime::Runtime::new().unwrap();
|
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
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```ignore
|
||||||
/// #[tokio::test]
|
/// #[tokio::test]
|
||||||
/// async fn my_test() {
|
/// async fn my_test() {
|
||||||
/// assert!(true);
|
/// assert!(true);
|
||||||
|
|||||||
+2
-1
@@ -48,6 +48,7 @@ rt-full = [
|
|||||||
# "timer",
|
# "timer",
|
||||||
"tokio-current-thread",
|
"tokio-current-thread",
|
||||||
"tokio-executor",
|
"tokio-executor",
|
||||||
|
"tokio-macros",
|
||||||
# "tokio-threadpool",
|
# "tokio-threadpool",
|
||||||
# "tokio-trace-core",
|
# "tokio-trace-core",
|
||||||
]
|
]
|
||||||
@@ -69,7 +70,7 @@ tokio-current-thread = { version = "0.2.0", optional = true, path = "../tokio-cu
|
|||||||
#tokio-fs = { version = "0.2.0", optional = true, path = "../tokio-fs" }
|
#tokio-fs = { version = "0.2.0", optional = true, path = "../tokio-fs" }
|
||||||
tokio-io = { version = "0.2.0", optional = true, path = "../tokio-io" }
|
tokio-io = { version = "0.2.0", optional = true, path = "../tokio-io" }
|
||||||
tokio-executor = { version = "0.2.0", optional = true, path = "../tokio-executor" }
|
tokio-executor = { version = "0.2.0", optional = true, path = "../tokio-executor" }
|
||||||
#tokio-macros = { version = "0.1.0", optional = true, path = "../tokio-macros" }
|
tokio-macros = { version = "0.1.0", optional = true, path = "../tokio-macros" }
|
||||||
tokio-reactor = { version = "0.2.0", optional = true, path = "../tokio-reactor" }
|
tokio-reactor = { version = "0.2.0", optional = true, path = "../tokio-reactor" }
|
||||||
tokio-sync = { version = "0.2.0", optional = true, path = "../tokio-sync" }
|
tokio-sync = { version = "0.2.0", optional = true, path = "../tokio-sync" }
|
||||||
#tokio-threadpool = { version = "0.2.0", optional = true, path = "../tokio-threadpool" }
|
#tokio-threadpool = { version = "0.2.0", optional = true, path = "../tokio-threadpool" }
|
||||||
|
|||||||
@@ -99,4 +99,7 @@ if_runtime! {
|
|||||||
|
|
||||||
pub use crate::executor::spawn;
|
pub use crate::executor::spawn;
|
||||||
pub use crate::runtime::run;
|
pub use crate::runtime::run;
|
||||||
|
|
||||||
|
#[cfg(not(test))] // Work around for rust-lang/rust#62127
|
||||||
|
pub use tokio_macros::main;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user