@@ -17,8 +17,8 @@ pub(crate) struct EventArgs {
1717#[ derive( Clone , Default , Debug ) ]
1818pub ( crate ) struct InstrumentArgs {
1919 level : Option < Level > ,
20- pub ( crate ) name : Option < LitStr > ,
21- target : Option < LitStr > ,
20+ pub ( crate ) name : Option < LitStrOrIdent > ,
21+ target : Option < LitStrOrIdent > ,
2222 pub ( crate ) parent : Option < Expr > ,
2323 pub ( crate ) follows_from : Option < Expr > ,
2424 pub ( crate ) skips : HashSet < Ident > ,
@@ -86,6 +86,8 @@ impl Parse for InstrumentArgs {
8686 // XXX: apparently we support names as either named args with an
8787 // sign, _or_ as unnamed string literals. That's weird, but
8888 // changing it is apparently breaking.
89+ // This also means that when using idents for name, it must be via
90+ // a named arg.
8991 if args. name . is_some ( ) {
9092 return Err ( input. error ( "expected only a single `name` argument" ) ) ;
9193 }
@@ -198,8 +200,32 @@ impl Parse for EventArgs {
198200 }
199201}
200202
203+ #[ derive( Debug , Clone ) ]
204+ pub ( super ) enum LitStrOrIdent {
205+ LitStr ( LitStr ) ,
206+ Ident ( Ident ) ,
207+ }
208+
209+ impl ToTokens for LitStrOrIdent {
210+ fn to_tokens ( & self , tokens : & mut TokenStream ) {
211+ match self {
212+ LitStrOrIdent :: LitStr ( target) => target. to_tokens ( tokens) ,
213+ LitStrOrIdent :: Ident ( ident) => ident. to_tokens ( tokens) ,
214+ }
215+ }
216+ }
217+
218+ impl Parse for LitStrOrIdent {
219+ fn parse ( input : ParseStream < ' _ > ) -> syn:: Result < Self > {
220+ input
221+ . parse :: < LitStr > ( )
222+ . map ( LitStrOrIdent :: LitStr )
223+ . or_else ( |_| input. parse :: < Ident > ( ) . map ( LitStrOrIdent :: Ident ) )
224+ }
225+ }
226+
201227struct StrArg < T > {
202- value : LitStr ,
228+ value : LitStrOrIdent ,
203229 _p : std:: marker:: PhantomData < T > ,
204230}
205231
0 commit comments