@@ -10,13 +10,15 @@ type AttributeArgs = syn::punctuated::Punctuated<syn::Meta, syn::Token![,]>;
10
10
enum RuntimeFlavor {
11
11
CurrentThread ,
12
12
Threaded ,
13
+ Local ,
13
14
}
14
15
15
16
impl RuntimeFlavor {
16
17
fn from_str ( s : & str ) -> Result < RuntimeFlavor , String > {
17
18
match s {
18
19
"current_thread" => Ok ( RuntimeFlavor :: CurrentThread ) ,
19
20
"multi_thread" => Ok ( RuntimeFlavor :: Threaded ) ,
21
+ "local" => Ok ( RuntimeFlavor :: Local ) ,
20
22
"single_thread" => Err ( "The single threaded runtime flavor is called `current_thread`." . to_string ( ) ) ,
21
23
"basic_scheduler" => Err ( "The `basic_scheduler` runtime flavor has been renamed to `current_thread`." . to_string ( ) ) ,
22
24
"threaded_scheduler" => Err ( "The `threaded_scheduler` runtime flavor has been renamed to `multi_thread`." . to_string ( ) ) ,
@@ -178,14 +180,14 @@ impl Configuration {
178
180
179
181
let flavor = self . flavor . unwrap_or ( self . default_flavor ) ;
180
182
let worker_threads = match ( flavor, self . worker_threads ) {
181
- ( F :: CurrentThread , Some ( ( _, worker_threads_span) ) ) => {
183
+ ( F :: CurrentThread | F :: Local , Some ( ( _, worker_threads_span) ) ) => {
182
184
let msg = format ! (
183
185
"The `worker_threads` option requires the `multi_thread` runtime flavor. Use `#[{}(flavor = \" multi_thread\" )]`" ,
184
186
self . macro_name( ) ,
185
187
) ;
186
188
return Err ( syn:: Error :: new ( worker_threads_span, msg) ) ;
187
189
}
188
- ( F :: CurrentThread , None ) => None ,
190
+ ( F :: CurrentThread | F :: Local , None ) => None ,
189
191
( F :: Threaded , worker_threads) if self . rt_multi_thread_available => {
190
192
worker_threads. map ( |( val, _span) | val)
191
193
}
@@ -207,7 +209,7 @@ impl Configuration {
207
209
) ;
208
210
return Err ( syn:: Error :: new ( start_paused_span, msg) ) ;
209
211
}
210
- ( F :: CurrentThread , Some ( ( start_paused, _) ) ) => Some ( start_paused) ,
212
+ ( F :: CurrentThread | F :: Local , Some ( ( start_paused, _) ) ) => Some ( start_paused) ,
211
213
( _, None ) => None ,
212
214
} ;
213
215
@@ -219,7 +221,7 @@ impl Configuration {
219
221
) ;
220
222
return Err ( syn:: Error :: new ( unhandled_panic_span, msg) ) ;
221
223
}
222
- ( F :: CurrentThread , Some ( ( unhandled_panic, _) ) ) => Some ( unhandled_panic) ,
224
+ ( F :: CurrentThread | F :: Local , Some ( ( unhandled_panic, _) ) ) => Some ( unhandled_panic) ,
223
225
( _, None ) => None ,
224
226
} ;
225
227
@@ -408,13 +410,22 @@ fn parse_knobs(mut input: ItemFn, is_test: bool, config: FinalConfig) -> TokenSt
408
410
. unwrap_or_else ( || Ident :: new ( "tokio" , last_stmt_start_span) . into_token_stream ( ) ) ;
409
411
410
412
let mut rt = match config. flavor {
411
- RuntimeFlavor :: CurrentThread => quote_spanned ! { last_stmt_start_span=>
412
- #crate_path:: runtime:: Builder :: new_current_thread( )
413
- } ,
413
+ RuntimeFlavor :: CurrentThread | RuntimeFlavor :: Local => {
414
+ quote_spanned ! { last_stmt_start_span=>
415
+ #crate_path:: runtime:: Builder :: new_current_thread( )
416
+ }
417
+ }
414
418
RuntimeFlavor :: Threaded => quote_spanned ! { last_stmt_start_span=>
415
419
#crate_path:: runtime:: Builder :: new_multi_thread( )
416
420
} ,
417
421
} ;
422
+
423
+ let build = if let RuntimeFlavor :: Local = config. flavor {
424
+ quote_spanned ! { last_stmt_start_span=> build_local( Default :: default ( ) ) }
425
+ } else {
426
+ quote_spanned ! { last_stmt_start_span=> build( ) }
427
+ } ;
428
+
418
429
if let Some ( v) = config. worker_threads {
419
430
rt = quote_spanned ! { last_stmt_start_span=> #rt. worker_threads( #v) } ;
420
431
}
@@ -441,7 +452,7 @@ fn parse_knobs(mut input: ItemFn, is_test: bool, config: FinalConfig) -> TokenSt
441
452
{
442
453
return #rt
443
454
. enable_all( )
444
- . build( )
455
+ . # build
445
456
. expect( "Failed building the Runtime" )
446
457
. block_on( #body_ident) ;
447
458
}
0 commit comments