From 2c03974a7e7cfec8d734caa6036d9a2461694818 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 6 Nov 2022 16:13:02 +0100 Subject: fix: allow injectable macro flag arguments without a interface argument --- macros/src/injectable/macro_args.rs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'macros/src') 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 { - let interface = input.parse::().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::().is_err() { + // Input doesn't begin with flags + + interface = input.parse::().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::()?; + } + + if input.is_empty() { return Ok(Self { interface, flags: Punctuated::new(), }); } - - input.parse::()?; - } - - if input.is_empty() { - return Ok(Self { - interface, - flags: Punctuated::new(), - }); } let flags = Punctuated::::parse_terminated(input)?; -- cgit v1.2.3-18-g5258