diff options
author | HampusM <hampus@hampusmat.com> | 2022-11-06 16:13:02 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-11-06 16:13:02 +0100 |
commit | 2c03974a7e7cfec8d734caa6036d9a2461694818 (patch) | |
tree | 572e532f96d4aa42bf95408bcca7a904efa39cfc /macros/src/injectable/macro_args.rs | |
parent | 3c993aa73c93f0fe335ced78d9709b39cdbd1935 (diff) |
fix: allow injectable macro flag arguments without a interface argument
Diffstat (limited to 'macros/src/injectable/macro_args.rs')
-rw-r--r-- | macros/src/injectable/macro_args.rs | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/macros/src/injectable/macro_args.rs b/macros/src/injectable/macro_args.rs index 50d4087..1dd06f8 100644 --- a/macros/src/injectable/macro_args.rs +++ b/macros/src/injectable/macro_args.rs @@ -17,26 +17,34 @@ impl Parse for InjectableMacroArgs { fn parse(input: ParseStream) -> syn::Result<Self> { - let interface = input.parse::<TypePath>().ok(); + let input_fork = input.fork(); - if interface.is_some() { - let comma_input_lookahead = input.lookahead1(); + let mut interface = None; - if !comma_input_lookahead.peek(Token![,]) { + if input_fork.parse::<MacroFlag>().is_err() { + // Input doesn't begin with flags + + interface = input.parse::<TypePath>().ok(); + + if interface.is_some() { + let comma_input_lookahead = input.lookahead1(); + + if !comma_input_lookahead.peek(Token![,]) { + return Ok(Self { + interface, + flags: Punctuated::new(), + }); + } + + input.parse::<Token![,]>()?; + } + + if input.is_empty() { return Ok(Self { interface, flags: Punctuated::new(), }); } - - input.parse::<Token![,]>()?; - } - - if input.is_empty() { - return Ok(Self { - interface, - flags: Punctuated::new(), - }); } let flags = Punctuated::<MacroFlag, Token![,]>::parse_terminated(input)?; |