diff options
author | HampusM <hampus@hampusmat.com> | 2023-08-03 15:09:46 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-08-03 15:15:29 +0200 |
commit | a3ccc2713bb5315123814cadd6c50275eee38e1c (patch) | |
tree | 22d50e174f3181bbddfd50840408e85e5a4adaac /macros/src/factory/declare_default_args.rs | |
parent | 14f1fc1837675e1771e220f848b46213462ae804 (diff) |
feat: add constructor name flag to injectable macro
Diffstat (limited to 'macros/src/factory/declare_default_args.rs')
-rw-r--r-- | macros/src/factory/declare_default_args.rs | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/macros/src/factory/declare_default_args.rs b/macros/src/factory/declare_default_args.rs index 269ef8f..f93d29d 100644 --- a/macros/src/factory/declare_default_args.rs +++ b/macros/src/factory/declare_default_args.rs @@ -31,12 +31,11 @@ impl Parse for DeclareDefaultFactoryMacroArgs let flags = Punctuated::<MacroFlag, Token![,]>::parse_terminated(input)?; for flag in &flags { - let flag_str = flag.flag.to_string(); + let name = flag.name().to_string(); - if !FACTORY_MACRO_FLAGS.contains(&flag_str.as_str()) { + if !FACTORY_MACRO_FLAGS.contains(&name.as_str()) { return Err(input.error(format!( - "Unknown flag '{}'. Expected one of [ {} ]", - flag_str, + "Unknown flag '{name}'. Expected one of [ {} ]", FACTORY_MACRO_FLAGS.join(",") ))); } @@ -44,7 +43,7 @@ impl Parse for DeclareDefaultFactoryMacroArgs let flag_names = flags .iter() - .map(|flag| flag.flag.to_string()) + .map(|flag| flag.name().to_string()) .collect::<Vec<_>>(); if let Some((dupe_flag_name, _)) = flag_names.iter().find_duplicate() { @@ -65,6 +64,7 @@ mod tests use syn::token::Dyn; use syn::{ parse2, + Lit, LitBool, Path, PathArguments, @@ -77,6 +77,7 @@ mod tests }; use super::*; + use crate::macro_flag::MacroFlagValue; #[test] fn can_parse_with_interface_only() -> Result<(), Box<dyn Error>> @@ -142,8 +143,11 @@ mod tests assert_eq!( dec_def_fac_args.flags, Punctuated::from_iter(vec![MacroFlag { - flag: format_ident!("threadsafe"), - is_on: LitBool::new(true, Span::call_site()) + name: format_ident!("threadsafe"), + value: MacroFlagValue::Literal(Lit::Bool(LitBool::new( + true, + Span::call_site() + ))) }]) ); @@ -182,12 +186,18 @@ mod tests dec_def_fac_args.flags, Punctuated::from_iter(vec![ MacroFlag { - flag: format_ident!("threadsafe"), - is_on: LitBool::new(true, Span::call_site()) + name: format_ident!("threadsafe"), + value: MacroFlagValue::Literal(Lit::Bool(LitBool::new( + true, + Span::call_site() + ))) }, MacroFlag { - flag: format_ident!("async"), - is_on: LitBool::new(false, Span::call_site()) + name: format_ident!("async"), + value: MacroFlagValue::Literal(Lit::Bool(LitBool::new( + false, + Span::call_site() + ))) } ]) ); |