diff options
author | HampusM <hampus@hampusmat.com> | 2022-08-29 20:52:56 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-08-29 21:01:32 +0200 |
commit | 080cc42bb1da09059dbc35049a7ded0649961e0c (patch) | |
tree | 307ee564124373616022c1ba2b4d5af80845cd92 /macros/src/injectable_macro_args.rs | |
parent | 6e31d8f9e46fece348f329763b39b9c6f2741c07 (diff) |
feat: implement async functionality
Diffstat (limited to 'macros/src/injectable_macro_args.rs')
-rw-r--r-- | macros/src/injectable_macro_args.rs | 55 |
1 files changed, 17 insertions, 38 deletions
diff --git a/macros/src/injectable_macro_args.rs b/macros/src/injectable_macro_args.rs index 43f8e11..6cc1d7e 100644 --- a/macros/src/injectable_macro_args.rs +++ b/macros/src/injectable_macro_args.rs @@ -1,49 +1,16 @@ use syn::parse::{Parse, ParseStream}; use syn::punctuated::Punctuated; -use syn::{braced, Ident, LitBool, Token, TypePath}; +use syn::{braced, Token, TypePath}; +use crate::macro_flag::MacroFlag; use crate::util::iterator_ext::IteratorExt; -pub const INJECTABLE_MACRO_FLAGS: &[&str] = &["no_doc_hidden"]; - -pub struct InjectableMacroFlag -{ - pub flag: Ident, - pub is_on: LitBool, -} - -impl Parse for InjectableMacroFlag -{ - fn parse(input: ParseStream) -> syn::Result<Self> - { - let input_forked = input.fork(); - - let flag: Ident = input_forked.parse()?; - - let flag_str = flag.to_string(); - - if !INJECTABLE_MACRO_FLAGS.contains(&flag_str.as_str()) { - return Err(input.error(format!( - "Unknown flag '{}'. Expected one of [ {} ]", - flag_str, - INJECTABLE_MACRO_FLAGS.join(",") - ))); - } - - input.parse::<Ident>()?; - - input.parse::<Token![=]>()?; - - let is_on: LitBool = input.parse()?; - - Ok(Self { flag, is_on }) - } -} +pub const INJECTABLE_MACRO_FLAGS: &[&str] = &["no_doc_hidden", "async"]; pub struct InjectableMacroArgs { pub interface: Option<TypePath>, - pub flags: Punctuated<InjectableMacroFlag, Token![,]>, + pub flags: Punctuated<MacroFlag, Token![,]>, } impl Parse for InjectableMacroArgs @@ -76,7 +43,19 @@ impl Parse for InjectableMacroArgs braced!(braced_content in input); - let flags = braced_content.parse_terminated(InjectableMacroFlag::parse)?; + let flags = braced_content.parse_terminated(MacroFlag::parse)?; + + for flag in &flags { + let flag_str = flag.flag.to_string(); + + if !INJECTABLE_MACRO_FLAGS.contains(&flag_str.as_str()) { + return Err(input.error(format!( + "Unknown flag '{}'. Expected one of [ {} ]", + flag_str, + INJECTABLE_MACRO_FLAGS.join(",") + ))); + } + } let flag_names = flags .iter() |