diff options
author | Sean McArthur <sean@seanmonstar.com> | 2019-09-24 11:39:36 -0700 |
---|---|---|
committer | Sean McArthur <sean@seanmonstar.com> | 2019-09-24 12:17:04 -0700 |
commit | 18cef1901fc805e7ef3443538c0931836891eab7 (patch) | |
tree | db68dc07a5917735a8361ae0a2a2b5d69bbfb6c6 /tokio-macros | |
parent | c81447fdccc31081b6af03015853dd8d05fd32f1 (diff) |
tokio: add `rt-current-thread` optional feature
- Adds a minimum `rt-current-thread` optional feature that exports
`tokio::runtime::current_thread`.
- Adds a `macros` optional feature to enable the `#[tokio::main]` and
`#[tokio::test]` attributes.
- Adjusts `#[tokio::main]` macro to select a runtime "automatically" if
a specific strategy isn't specified. Allows using the macro with only
the rt-current-thread feature.
Diffstat (limited to 'tokio-macros')
-rw-r--r-- | tokio-macros/src/lib.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/tokio-macros/src/lib.rs b/tokio-macros/src/lib.rs index 9a33c5fd..d8eedb02 100644 --- a/tokio-macros/src/lib.rs +++ b/tokio-macros/src/lib.rs @@ -49,6 +49,7 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { enum RuntimeType { Single, Multi, + Auto, } let input = syn::parse_macro_input!(item as syn::ItemFn); @@ -71,7 +72,7 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { .into(); } - let mut runtime = RuntimeType::Multi; + let mut runtime = RuntimeType::Auto; for arg in args { if let syn::NestedMeta::Meta(syn::Meta::Path(path)) = arg { @@ -106,6 +107,13 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { rt.block_on(async { #body }) } }, + RuntimeType::Auto => quote! { + #(#attrs)* + fn #name() #ret { + let mut rt = tokio::runtime::__main::Runtime::new().unwrap(); + rt.block_on(async { #body }) + } + }, }; result.into() |