@@ -53,6 +53,7 @@ impl UnhandledPanic {
5353}
5454
5555struct FinalConfig {
56+ name : Option < String > ,
5657 flavor : RuntimeFlavor ,
5758 worker_threads : Option < usize > ,
5859 start_paused : Option < bool > ,
@@ -62,6 +63,7 @@ struct FinalConfig {
6263
6364/// Config used in case of the attribute not being able to build a valid config
6465const DEFAULT_ERROR_CONFIG : FinalConfig = FinalConfig {
66+ name : None ,
6567 flavor : RuntimeFlavor :: CurrentThread ,
6668 worker_threads : None ,
6769 start_paused : None ,
@@ -70,6 +72,7 @@ const DEFAULT_ERROR_CONFIG: FinalConfig = FinalConfig {
7072} ;
7173
7274struct Configuration {
75+ name : Option < String > ,
7376 rt_multi_thread_available : bool ,
7477 default_flavor : RuntimeFlavor ,
7578 flavor : Option < RuntimeFlavor > ,
@@ -83,6 +86,7 @@ struct Configuration {
8386impl Configuration {
8487 fn new ( is_test : bool , rt_multi_thread : bool ) -> Self {
8588 Configuration {
89+ name : None ,
8690 rt_multi_thread_available : rt_multi_thread,
8791 default_flavor : match is_test {
8892 true => RuntimeFlavor :: CurrentThread ,
@@ -97,6 +101,16 @@ impl Configuration {
97101 }
98102 }
99103
104+ fn set_name ( & mut self , name : syn:: Lit , span : Span ) -> Result < ( ) , syn:: Error > {
105+ if self . name . is_some ( ) {
106+ return Err ( syn:: Error :: new ( span, "`name` set multiple times." ) ) ;
107+ }
108+
109+ let runtime_name = parse_string ( name, span, "name" ) ?;
110+ self . name = Some ( runtime_name) ;
111+ Ok ( ( ) )
112+ }
113+
100114 fn set_flavor ( & mut self , runtime : syn:: Lit , span : Span ) -> Result < ( ) , syn:: Error > {
101115 if self . flavor . is_some ( ) {
102116 return Err ( syn:: Error :: new ( span, "`flavor` set multiple times." ) ) ;
@@ -227,6 +241,7 @@ impl Configuration {
227241 } ;
228242
229243 Ok ( FinalConfig {
244+ name : self . name . clone ( ) ,
230245 crate_name : self . crate_name . clone ( ) ,
231246 flavor,
232247 worker_threads,
@@ -372,9 +387,12 @@ fn build_config(
372387 config
373388 . set_unhandled_panic ( lit. clone ( ) , syn:: spanned:: Spanned :: span ( lit) ) ?;
374389 }
390+ "name" => {
391+ config. set_name ( lit. clone ( ) , syn:: spanned:: Spanned :: span ( lit) ) ?;
392+ }
375393 name => {
376394 let msg = format ! (
377- "Unknown attribute {name} is specified; expected one of: `flavor`, `worker_threads`, `start_paused`, `crate`, `unhandled_panic`" ,
395+ "Unknown attribute {name} is specified; expected one of: `flavor`, `worker_threads`, `start_paused`, `crate`, `unhandled_panic`, `name`. " ,
378396 ) ;
379397 return Err ( syn:: Error :: new_spanned ( namevalue, msg) ) ;
380398 }
@@ -397,11 +415,12 @@ fn build_config(
397415 "Set the runtime flavor with #[{macro_name}(flavor = \" current_thread\" )]."
398416 )
399417 }
400- "flavor" | "worker_threads" | "start_paused" | "crate" | "unhandled_panic" => {
418+ "flavor" | "worker_threads" | "start_paused" | "crate" | "unhandled_panic"
419+ | "name" => {
401420 format ! ( "The `{name}` attribute requires an argument." )
402421 }
403422 name => {
404- format ! ( "Unknown attribute {name} is specified; expected one of: `flavor`, `worker_threads`, `start_paused`, `crate`, `unhandled_panic`." )
423+ format ! ( "Unknown attribute {name} is specified; expected one of: `flavor`, `worker_threads`, `start_paused`, `crate`, `unhandled_panic`, `name` ." )
405424 }
406425 } ;
407426 return Err ( syn:: Error :: new_spanned ( path, msg) ) ;
@@ -478,6 +497,9 @@ fn parse_knobs(mut input: ItemFn, is_test: bool, config: FinalConfig) -> TokenSt
478497 let unhandled_panic = v. into_tokens ( & crate_path) ;
479498 rt = quote_spanned ! { last_stmt_start_span=> #rt. unhandled_panic( #unhandled_panic) } ;
480499 }
500+ if let Some ( v) = config. name {
501+ rt = quote_spanned ! { last_stmt_start_span=> #rt. name( #v) } ;
502+ }
481503
482504 let generated_attrs = if is_test {
483505 quote ! {
0 commit comments