@@ -46,7 +46,12 @@ use proc_macro::TokenStream;
46
46
/// Awaiting on other futures from the function provided here will not
47
47
/// perform as fast as those spawned as workers.
48
48
///
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
50
55
///
51
56
/// To use the multi-threaded runtime, the macro can be configured using
52
57
///
@@ -61,7 +66,7 @@ use proc_macro::TokenStream;
61
66
/// Note: The multi-threaded runtime requires the `rt-multi-thread` feature
62
67
/// flag.
63
68
///
64
- /// # Current thread runtime
69
+ /// ## Current- thread
65
70
///
66
71
/// To use the single-threaded runtime known as the `current_thread` runtime,
67
72
/// the macro can be configured using
@@ -71,13 +76,24 @@ use proc_macro::TokenStream;
71
76
/// # async fn main() {}
72
77
/// ```
73
78
///
74
- /// ## Function arguments:
79
+ /// ## Local
75
80
///
76
- /// Arguments are allowed for any functions aside from `main` which is special
81
+ /// [Unstable API][unstable] only.
77
82
///
78
- /// ## Usage
83
+ /// To use the [local runtime], the macro can be configured using
79
84
///
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
81
97
///
82
98
/// ```rust
83
99
/// #[tokio::main]
@@ -100,7 +116,7 @@ use proc_macro::TokenStream;
100
116
/// }
101
117
/// ```
102
118
///
103
- /// ### Using current thread runtime
119
+ /// ## Using the current- thread runtime
104
120
///
105
121
/// The basic scheduler is single-threaded.
106
122
///
@@ -125,7 +141,36 @@ use proc_macro::TokenStream;
125
141
/// }
126
142
/// ```
127
143
///
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
129
174
///
130
175
/// ```rust
131
176
/// #[tokio::main(worker_threads = 2)]
@@ -149,7 +194,7 @@ use proc_macro::TokenStream;
149
194
/// }
150
195
/// ```
151
196
///
152
- /// ### Configure the runtime to start with time paused
197
+ /// ## Configure the runtime to start with time paused
153
198
///
154
199
/// ```rust
155
200
/// #[tokio::main(flavor = "current_thread", start_paused = true)]
@@ -175,7 +220,7 @@ use proc_macro::TokenStream;
175
220
///
176
221
/// Note that `start_paused` requires the `test-util` feature to be enabled.
177
222
///
178
- /// ### Rename package
223
+ /// ## Rename package
179
224
///
180
225
/// ```rust
181
226
/// use tokio as tokio1;
@@ -202,7 +247,7 @@ use proc_macro::TokenStream;
202
247
/// }
203
248
/// ```
204
249
///
205
- /// ### Configure unhandled panic behavior
250
+ /// ## Configure unhandled panic behavior
206
251
///
207
252
/// Available options are `shutdown_runtime` and `ignore`. For more details, see
208
253
/// [`Builder::unhandled_panic`].
@@ -247,6 +292,7 @@ use proc_macro::TokenStream;
247
292
///
248
293
/// [`Builder::unhandled_panic`]: ../tokio/runtime/struct.Builder.html#method.unhandled_panic
249
294
/// [unstable]: ../tokio/index.html#unstable-features
295
+ /// [local runtime]: ../tokio/runtime/struct.LocalRuntime.html
250
296
#[ proc_macro_attribute]
251
297
pub fn main ( args : TokenStream , item : TokenStream ) -> TokenStream {
252
298
entry:: main ( args. into ( ) , item. into ( ) , true ) . into ( )
0 commit comments