From 7de7f73963a266cceff85d6ab71c3256e5d382ec Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 17 Sep 2022 18:33:43 +0200 Subject: feat!: allow factories to access async DI container BREAKING CHANGE: The to_factory & to_default_factory methods of AsyncBindingBuilder now expects a function returning a factory function --- macros/src/lib.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'macros') diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 4c815db..79b1a1b 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -194,7 +194,7 @@ pub fn factory(args_stream: TokenStream, type_alias_stream: TokenStream) -> Toke let FactoryMacroArgs { flags } = parse(args_stream).unwrap(); - let is_async = flags + let is_threadsafe = flags .iter() .find(|flag| flag.flag.to_string().as_str() == "threadsafe") .map_or(false, |flag| flag.is_on.value); @@ -202,24 +202,27 @@ pub fn factory(args_stream: TokenStream, type_alias_stream: TokenStream) -> Toke let factory_type_alias::FactoryTypeAlias { type_alias, factory_interface, - arg_types, - return_type, + arg_types: _, + return_type: _, } = parse(type_alias_stream).unwrap(); - let decl_interfaces = if is_async { + let decl_interfaces = if is_threadsafe { quote! { syrette::declare_interface!( syrette::castable_factory::threadsafe::ThreadsafeCastableFactory< - #arg_types, - #return_type - > -> #factory_interface, + (std::sync::Arc,), + #factory_interface + > -> syrette::interfaces::factory::IFactory< + (std::sync::Arc,), + #factory_interface + >, async = true ); syrette::declare_interface!( syrette::castable_factory::threadsafe::ThreadsafeCastableFactory< - #arg_types, - #return_type + (std::sync::Arc,), + #factory_interface > -> syrette::interfaces::any_factory::AnyThreadsafeFactory, async = true ); @@ -300,17 +303,20 @@ pub fn declare_default_factory(args_stream: TokenStream) -> TokenStream return quote! { syrette::declare_interface!( syrette::castable_factory::threadsafe::ThreadsafeCastableFactory< - (), + (std::sync::Arc,), #interface, - > -> syrette::interfaces::factory::IFactory<(), #interface>, + > -> syrette::interfaces::factory::IFactory< + (std::sync::Arc,), + #interface + >, async = true ); syrette::declare_interface!( syrette::castable_factory::threadsafe::ThreadsafeCastableFactory< - (), + (std::sync::Arc,), #interface, - > -> syrette::interfaces::any_factory::AnyFactory, + > -> syrette::interfaces::any_factory::AnyThreadsafeFactory, async = true ); } -- cgit v1.2.3-18-g5258