@@ -46,7 +46,12 @@ use proc_macro::TokenStream;
4646/// Awaiting on other futures from the function provided here will not
4747/// perform as fast as those spawned as workers.
4848///
49- /// # Multi-threaded runtime
49+ /// # Runtime flavors
50+ ///
51+ /// The macro can be configured with a `flavor` parameter to select
52+ /// different runtime configurations.
53+ ///
54+ /// ## Multi-threaded
5055///
5156/// To use the multi-threaded runtime, the macro can be configured using
5257///
@@ -61,7 +66,7 @@ use proc_macro::TokenStream;
6166/// Note: The multi-threaded runtime requires the `rt-multi-thread` feature
6267/// flag.
6368///
64- /// # Current thread runtime
69+ /// ## Current- thread
6570///
6671/// To use the single-threaded runtime known as the `current_thread` runtime,
6772/// the macro can be configured using
@@ -71,13 +76,24 @@ use proc_macro::TokenStream;
7176/// # async fn main() {}
7277/// ```
7378///
74- /// ## Function arguments:
79+ /// ## Local
7580///
76- /// Arguments are allowed for any functions aside from `main` which is special
81+ /// [Unstable API][unstable] only.
7782///
78- /// ## Usage
83+ /// To use the [local runtime], the macro can be configured using
7984///
80- /// ### Using the multi-thread runtime
85+ /// ```
86+ /// #[tokio::main(flavor = "local")]
87+ /// # async fn main() {}
88+ /// ```
89+ ///
90+ /// # Function arguments
91+ ///
92+ /// Arguments are allowed for any functions, aside from `main` which is special.
93+ ///
94+ /// # Usage
95+ ///
96+ /// ## Using the multi-threaded runtime
8197///
8298/// ```rust
8399/// #[tokio::main]
@@ -100,7 +116,7 @@ use proc_macro::TokenStream;
100116/// }
101117/// ```
102118///
103- /// ### Using current thread runtime
119+ /// ## Using the current- thread runtime
104120///
105121/// The basic scheduler is single-threaded.
106122///
@@ -125,7 +141,36 @@ use proc_macro::TokenStream;
125141/// }
126142/// ```
127143///
128- /// ### Set number of worker threads
144+ /// ## Using the local runtime
145+ ///
146+ /// Available in the [unstable API][unstable] only.
147+ ///
148+ /// The [local runtime] is similar to the current-thread runtime but
149+ /// supports [`task::spawn_local`](../tokio/task/fn.spawn_local.html).
150+ ///
151+ /// ```rust
152+ /// #[tokio::main(flavor = "local")]
153+ /// async fn main() {
154+ /// println!("Hello world");
155+ /// }
156+ /// ```
157+ ///
158+ /// Equivalent code not using `#[tokio::main]`
159+ ///
160+ /// ```rust
161+ /// fn main() {
162+ /// tokio::runtime::Builder::new_current_thread()
163+ /// .enable_all()
164+ /// .build_local(tokio::runtime::LocalOptions::default())
165+ /// .unwrap()
166+ /// .block_on(async {
167+ /// println!("Hello world");
168+ /// })
169+ /// }
170+ /// ```
171+ ///
172+ ///
173+ /// ## Set number of worker threads
129174///
130175/// ```rust
131176/// #[tokio::main(worker_threads = 2)]
@@ -149,7 +194,7 @@ use proc_macro::TokenStream;
149194/// }
150195/// ```
151196///
152- /// ### Configure the runtime to start with time paused
197+ /// ## Configure the runtime to start with time paused
153198///
154199/// ```rust
155200/// #[tokio::main(flavor = "current_thread", start_paused = true)]
@@ -175,7 +220,7 @@ use proc_macro::TokenStream;
175220///
176221/// Note that `start_paused` requires the `test-util` feature to be enabled.
177222///
178- /// ### Rename package
223+ /// ## Rename package
179224///
180225/// ```rust
181226/// use tokio as tokio1;
@@ -202,7 +247,7 @@ use proc_macro::TokenStream;
202247/// }
203248/// ```
204249///
205- /// ### Configure unhandled panic behavior
250+ /// ## Configure unhandled panic behavior
206251///
207252/// Available options are `shutdown_runtime` and `ignore`. For more details, see
208253/// [`Builder::unhandled_panic`].
@@ -247,6 +292,7 @@ use proc_macro::TokenStream;
247292///
248293/// [`Builder::unhandled_panic`]: ../tokio/runtime/struct.Builder.html#method.unhandled_panic
249294/// [unstable]: ../tokio/index.html#unstable-features
295+ /// [local runtime]: ../tokio/runtime/struct.LocalRuntime.html
250296#[ proc_macro_attribute]
251297pub fn main ( args : TokenStream , item : TokenStream ) -> TokenStream {
252298 entry:: main ( args. into ( ) , item. into ( ) , true ) . into ( )
0 commit comments