diff options
author | HampusM <hampus@hampusmat.com> | 2022-09-17 18:33:43 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-09-17 18:33:43 +0200 |
commit | 7de7f73963a266cceff85d6ab71c3256e5d382ec (patch) | |
tree | 67575870945b7ed0a5eeb99ccba79327598b3e02 /macros/src/lib.rs | |
parent | 8651f84f205da7a89f2fc7333d1dd8de0d80a22b (diff) |
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
Diffstat (limited to 'macros/src/lib.rs')
-rw-r--r-- | macros/src/lib.rs | 32 |
1 files changed, 19 insertions, 13 deletions
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<syrette::async_di_container::AsyncDIContainer>,), + #factory_interface + > -> syrette::interfaces::factory::IFactory< + (std::sync::Arc<syrette::async_di_container::AsyncDIContainer>,), + #factory_interface + >, async = true ); syrette::declare_interface!( syrette::castable_factory::threadsafe::ThreadsafeCastableFactory< - #arg_types, - #return_type + (std::sync::Arc<syrette::async_di_container::AsyncDIContainer>,), + #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<syrette::async_di_container::AsyncDIContainer>,), #interface, - > -> syrette::interfaces::factory::IFactory<(), #interface>, + > -> syrette::interfaces::factory::IFactory< + (std::sync::Arc<syrette::async_di_container::AsyncDIContainer>,), + #interface + >, async = true ); syrette::declare_interface!( syrette::castable_factory::threadsafe::ThreadsafeCastableFactory< - (), + (std::sync::Arc<syrette::async_di_container::AsyncDIContainer>,), #interface, - > -> syrette::interfaces::any_factory::AnyFactory, + > -> syrette::interfaces::any_factory::AnyThreadsafeFactory, async = true ); } |