diff options
-rw-r--r-- | examples/async-factory/main.rs | 2 | ||||
-rw-r--r-- | macros/src/factory/macro_args.rs | 44 | ||||
-rw-r--r-- | macros/src/lib.rs | 13 | ||||
-rw-r--r-- | src/di_container/asynchronous/binding/builder.rs | 4 |
4 files changed, 10 insertions, 53 deletions
diff --git a/examples/async-factory/main.rs b/examples/async-factory/main.rs index d368a32..3335700 100644 --- a/examples/async-factory/main.rs +++ b/examples/async-factory/main.rs @@ -16,7 +16,7 @@ trait IFoo: Send + Sync fn bar(&self); } -#[factory(async = true)] +#[factory] type IFooFactory = dyn Fn(i32) -> BoxFuture<'static, TransientPtr<dyn IFoo>> + Send + Sync; diff --git a/macros/src/factory/macro_args.rs b/macros/src/factory/macro_args.rs index cb2cbc9..76b29a2 100644 --- a/macros/src/factory/macro_args.rs +++ b/macros/src/factory/macro_args.rs @@ -5,7 +5,7 @@ use syn::Token; use crate::macro_flag::MacroFlag; use crate::util::iterator_ext::IteratorExt; -pub const FACTORY_MACRO_FLAGS: &[&str] = &["threadsafe", "async"]; +pub const FACTORY_MACRO_FLAGS: &[&str] = &["threadsafe"]; pub struct FactoryMacroArgs { @@ -59,7 +59,7 @@ mod tests fn can_parse_with_single_flag() -> Result<(), Box<dyn Error>> { let input_args = quote! { - async = true + threadsafe = true }; let factory_macro_args = parse2::<FactoryMacroArgs>(input_args)?; @@ -67,7 +67,7 @@ mod tests assert_eq!( factory_macro_args.flags, Punctuated::from_iter(vec![MacroFlag { - name: format_ident!("async"), + name: format_ident!("threadsafe"), value: MacroFlagValue::Literal(Lit::Bool(LitBool::new( true, Span::call_site() @@ -79,42 +79,10 @@ mod tests } #[test] - fn can_parse_with_multiple_flags() -> Result<(), Box<dyn Error>> - { - let input_args = quote! { - async = true, threadsafe = false - }; - - let factory_macro_args = parse2::<FactoryMacroArgs>(input_args)?; - - assert_eq!( - factory_macro_args.flags, - Punctuated::from_iter(vec![ - MacroFlag { - name: format_ident!("async"), - value: MacroFlagValue::Literal(Lit::Bool(LitBool::new( - true, - Span::call_site() - ))) - }, - MacroFlag { - name: format_ident!("threadsafe"), - value: MacroFlagValue::Literal(Lit::Bool(LitBool::new( - false, - Span::call_site() - ))) - } - ]) - ); - - Ok(()) - } - - #[test] fn cannot_parse_with_invalid_flag() { let input_args = quote! { - async = true, threadsafe = false, foo = true + threadsafe = false, foo = true }; assert!(parse2::<FactoryMacroArgs>(input_args).is_err()); @@ -126,7 +94,7 @@ mod tests assert!( // Formatting is weird without this comment parse2::<FactoryMacroArgs>(quote! { - async = true, threadsafe = false, async = true + threadsafe = true, threadsafe = true }) .is_err() ); @@ -134,7 +102,7 @@ mod tests assert!( // Formatting is weird without this comment parse2::<FactoryMacroArgs>(quote! { - async = true, threadsafe = false, async = false + threadsafe = true, threadsafe = false }) .is_err() ); diff --git a/macros/src/lib.rs b/macros/src/lib.rs index b11186e..e9aaeb0 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -253,7 +253,6 @@ pub fn injectable(args_stream: TokenStream, input_stream: TokenStream) -> TokenS /// /// # Flags /// - `threadsafe` - Mark as threadsafe. -/// - `async` - Mark as async. Infers the `threadsafe` flag. /// /// # Examples /// ``` @@ -294,22 +293,12 @@ pub fn factory(args_stream: TokenStream, input_stream: TokenStream) -> TokenStre let FactoryMacroArgs { flags } = parse(args_stream).unwrap_or_abort(); - let mut is_threadsafe = flags + let is_threadsafe = flags .iter() .find(|flag| flag.name() == "threadsafe") .map_or(Ok(false), MacroFlag::get_bool) .unwrap_or_abort(); - let is_async = flags - .iter() - .find(|flag| flag.name() == "async") - .map_or(Ok(false), MacroFlag::get_bool) - .unwrap_or_abort(); - - if is_async { - is_threadsafe = true; - } - let FactoryTypeAlias { type_alias, factory_interface, diff --git a/src/di_container/asynchronous/binding/builder.rs b/src/di_container/asynchronous/binding/builder.rs index 306d196..9fa5115 100644 --- a/src/di_container/asynchronous/binding/builder.rs +++ b/src/di_container/asynchronous/binding/builder.rs @@ -238,7 +238,7 @@ where /// # /// # impl Foo for Bar {} /// # - /// # #[factory(async = true)] + /// # #[factory] /// # type FooFactory = dyn Fn(i32, String) -> BoxFuture< /// # 'static, /// # TransientPtr<dyn Foo> @@ -602,7 +602,7 @@ mod tests use crate::{self as syrette, factory}; #[rustfmt::skip] - #[factory(async = true)] + #[factory] type IUserManagerFactory = dyn Fn(String) -> BoxFuture< 'static, TransientPtr<dyn subjects_async::IUserManager> |