diff options
author | HampusM <hampus@hampusmat.com> | 2022-09-24 16:14:45 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-09-24 16:14:45 +0200 |
commit | 2a44ec3ffdcd78b23ac31b722b4312774d643c3a (patch) | |
tree | d3056a1fffe6311f863c4d683cc3444507c3e7d8 /macros/src/factory | |
parent | 695f90bf900015df1e2728445f833dabced838a9 (diff) |
refactor!: remove repetition of declaring factory interfaces
BREAKING CHANGE: The to_default_factory method of the blocking and async DI containers now expect a function returning another function
Diffstat (limited to 'macros/src/factory')
-rw-r--r-- | macros/src/factory/build_declare_interfaces.rs | 52 | ||||
-rw-r--r-- | macros/src/factory/mod.rs | 1 |
2 files changed, 53 insertions, 0 deletions
diff --git a/macros/src/factory/build_declare_interfaces.rs b/macros/src/factory/build_declare_interfaces.rs new file mode 100644 index 0000000..ac4ddd6 --- /dev/null +++ b/macros/src/factory/build_declare_interfaces.rs @@ -0,0 +1,52 @@ +use proc_macro2::TokenStream; +use quote::quote; + +use crate::fn_trait::FnTrait; + +pub fn build_declare_factory_interfaces( + factory_interface: &FnTrait, + is_threadsafe: bool, +) -> TokenStream +{ + if is_threadsafe { + quote! { + syrette::declare_interface!( + syrette::castable_factory::threadsafe::ThreadsafeCastableFactory< + (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< + (std::sync::Arc<syrette::async_di_container::AsyncDIContainer>,), + #factory_interface + > -> syrette::interfaces::any_factory::AnyThreadsafeFactory, + async = true + ); + } + } else { + quote! { + syrette::declare_interface!( + syrette::castable_factory::blocking::CastableFactory< + (std::rc::Rc<syrette::di_container::DIContainer>,), + #factory_interface + > -> syrette::interfaces::factory::IFactory< + (std::rc::Rc<syrette::di_container::DIContainer>,), + #factory_interface + > + ); + + syrette::declare_interface!( + syrette::castable_factory::blocking::CastableFactory< + (std::rc::Rc<syrette::di_container::DIContainer>,), + #factory_interface + > -> syrette::interfaces::any_factory::AnyFactory + ); + } + } +} diff --git a/macros/src/factory/mod.rs b/macros/src/factory/mod.rs index a8947c5..18bad8f 100644 --- a/macros/src/factory/mod.rs +++ b/macros/src/factory/mod.rs @@ -1,3 +1,4 @@ +pub mod build_declare_interfaces; pub mod declare_default_args; pub mod macro_args; pub mod type_alias; |