summaryrefslogtreecommitdiffstats
path: root/tokio-macros
diff options
context:
space:
mode:
authorxd009642 <danielmckenna93@gmail.com>2020-07-24 16:32:15 +0100
committerGitHub <noreply@github.com>2020-07-24 08:32:15 -0700
commit844d9c6acbdf1fe109c0f6e73130ef933e6b7716 (patch)
tree78cb527dcf0a8216469835c3ecc4962662f83da3 /tokio-macros
parentff7125ec7b4fe009b80cc033edbf338883eb0435 (diff)
rt: document how #[tokio::main] is expanded (#2683)
Diffstat (limited to 'tokio-macros')
-rw-r--r--tokio-macros/src/lib.rs87
1 files changed, 83 insertions, 4 deletions
diff --git a/tokio-macros/src/lib.rs b/tokio-macros/src/lib.rs
index b1742d48..64cdc4f1 100644
--- a/tokio-macros/src/lib.rs
+++ b/tokio-macros/src/lib.rs
@@ -24,7 +24,9 @@ mod select;
use proc_macro::TokenStream;
-/// Marks async function to be executed by selected runtime.
+/// Marks async function to be executed by selected runtime. This macro helps set up a `Runtime`
+/// without requiring the user to use [Runtime](../tokio/runtime/struct.Runtime.html) or
+/// [Builder](../tokio/runtime/struct.builder.html) directly.
///
/// ## Options:
///
@@ -47,15 +49,46 @@ use proc_macro::TokenStream;
/// }
/// ```
///
+/// Equivalent code not using `#[tokio::main]`
+///
+/// ```rust
+/// fn main() {
+/// tokio::runtime::Builder::new()
+/// .threaded_scheduler()
+/// .enable_all()
+/// .build()
+/// .unwrap()
+/// .block_on(async {
+/// println!("Hello world");
+/// })
+/// }
+/// ```
+///
/// ### Set number of core threads
///
/// ```rust
-/// #[tokio::main(core_threads = 1)]
+/// #[tokio::main(core_threads = 2)]
/// async fn main() {
/// println!("Hello world");
/// }
/// ```
///
+/// Equivalent code not using `#[tokio::main]`
+///
+/// ```rust
+/// fn main() {
+/// tokio::runtime::Builder::new()
+/// .threaded_scheduler()
+/// .core_threads(2)
+/// .enable_all()
+/// .build()
+/// .unwrap()
+/// .block_on(async {
+/// println!("Hello world");
+/// })
+/// }
+/// ```
+///
/// ### NOTE:
///
/// If you rename the tokio crate in your dependencies this macro
@@ -69,7 +102,9 @@ pub fn main_threaded(args: TokenStream, item: TokenStream) -> TokenStream {
entry::main(args, item, true)
}
-/// Marks async function to be executed by selected runtime.
+/// Marks async function to be executed by selected runtime. This macro helps set up a `Runtime`
+/// without requiring the user to use [Runtime](../tokio/runtime/struct.Runtime.html) or
+/// [Builder](../tokio/runtime/struct.builder.html) directly.
///
/// ## Options:
///
@@ -91,6 +126,18 @@ pub fn main_threaded(args: TokenStream, item: TokenStream) -> TokenStream {
/// }
/// ```
///
+/// Equivalent code not using `#[tokio::main]`
+///
+/// ```rust
+/// fn main() {
+/// tokio::runtime::Runtime::new()
+/// .unwrap()
+/// .block_on(async {
+/// println!("Hello world");
+/// })
+/// }
+/// ```
+///
/// ### Select runtime
///
/// ```rust
@@ -100,6 +147,21 @@ pub fn main_threaded(args: TokenStream, item: TokenStream) -> TokenStream {
/// }
/// ```
///
+/// Equivalent code not using `#[tokio::main]`
+///
+/// ```rust
+/// fn main() {
+/// tokio::runtime::Builder::new()
+/// .basic_scheduler()
+/// .enable_all()
+/// .build()
+/// .unwrap()
+/// .block_on(async {
+/// println!("Hello world");
+/// })
+/// }
+/// ```
+///
/// ### NOTE:
///
/// If you rename the tokio crate in your dependencies this macro
@@ -113,7 +175,9 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
entry::old::main(args, item)
}
-/// Marks async function to be executed by selected runtime.
+/// Marks async function to be executed by selected runtime. This macro helps set up a `Runtime`
+/// without requiring the user to use [Runtime](../tokio/runtime/struct.Runtime.html) or
+/// [Builder](../tokio/runtime/struct.builder.html) directly.
///
/// ## Options:
///
@@ -134,6 +198,21 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
/// }
/// ```
///
+/// Equivalent code not using `#[tokio::main]`
+///
+/// ```rust
+/// fn main() {
+/// tokio::runtime::Builder::new()
+/// .basic_scheduler()
+/// .enable_all()
+/// .build()
+/// .unwrap()
+/// .block_on(async {
+/// println!("Hello world");
+/// })
+/// }
+/// ```
+///
/// ### NOTE:
///
/// If you rename the tokio crate in your dependencies this macro