From 2a44ec3ffdcd78b23ac31b722b4312774d643c3a Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 24 Sep 2022 16:14:45 +0200 Subject: 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 --- macros/src/factory/build_declare_interfaces.rs | 52 ++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 macros/src/factory/build_declare_interfaces.rs (limited to 'macros/src/factory/build_declare_interfaces.rs') 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,), + #factory_interface + > -> syrette::interfaces::factory::IFactory< + (std::sync::Arc,), + #factory_interface + >, + async = true + ); + + syrette::declare_interface!( + syrette::castable_factory::threadsafe::ThreadsafeCastableFactory< + (std::sync::Arc,), + #factory_interface + > -> syrette::interfaces::any_factory::AnyThreadsafeFactory, + async = true + ); + } + } else { + quote! { + syrette::declare_interface!( + syrette::castable_factory::blocking::CastableFactory< + (std::rc::Rc,), + #factory_interface + > -> syrette::interfaces::factory::IFactory< + (std::rc::Rc,), + #factory_interface + > + ); + + syrette::declare_interface!( + syrette::castable_factory::blocking::CastableFactory< + (std::rc::Rc,), + #factory_interface + > -> syrette::interfaces::any_factory::AnyFactory + ); + } + } +} -- cgit v1.2.3-18-g5258