aboutsummaryrefslogtreecommitdiff
path: root/macros/src/lib.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-09-12 20:22:13 +0200
committerHampusM <hampus@hampusmat.com>2022-09-17 14:33:15 +0200
commitc1e682c25c24be3174d44ceb95b0537c38299d0c (patch)
tree6e59f37e1b98e68fad2e3e2fe4a428ac97fcf8b4 /macros/src/lib.rs
parente8e48906a3899e71c9c9d86a3d4528cb7d17e5b9 (diff)
feat!: allow factories access to DI container
BREAKING CHANGE: Factory types should now be written with the Fn trait instead of the IFactory trait and the to_factory & to_default_factory methods of BindingBuilder now expect a function returning a factory function
Diffstat (limited to 'macros/src/lib.rs')
-rw-r--r--macros/src/lib.rs26
1 files changed, 17 insertions, 9 deletions
diff --git a/macros/src/lib.rs b/macros/src/lib.rs
index 25f3c5c..4c815db 100644
--- a/macros/src/lib.rs
+++ b/macros/src/lib.rs
@@ -13,6 +13,7 @@ mod declare_interface_args;
mod dependency;
mod factory_macro_args;
mod factory_type_alias;
+mod fn_trait;
mod injectable_impl;
mod injectable_macro_args;
mod libs;
@@ -166,6 +167,7 @@ pub fn injectable(args_stream: TokenStream, impl_stream: TokenStream) -> TokenSt
/// ```
/// # use syrette::factory;
/// # use syrette::interfaces::factory::IFactory;
+/// # use syrette::ptr::TransientPtr;
/// #
/// # trait IConfigurator {}
/// #
@@ -182,7 +184,7 @@ pub fn injectable(args_stream: TokenStream, impl_stream: TokenStream) -> TokenSt
/// # impl IConfigurator for Configurator {}
/// #
/// #[factory]
-/// type IConfiguratorFactory = dyn IFactory<(Vec<String>,), dyn IConfigurator>;
+/// type IConfiguratorFactory = dyn Fn(Vec<String>) -> TransientPtr<dyn IConfigurator>;
/// ```
#[proc_macro_attribute]
#[cfg(feature = "factory")]
@@ -226,15 +228,18 @@ pub fn factory(args_stream: TokenStream, type_alias_stream: TokenStream) -> Toke
quote! {
syrette::declare_interface!(
syrette::castable_factory::blocking::CastableFactory<
- #arg_types,
- #return_type
- > -> #factory_interface
+ (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<
- #arg_types,
- #return_type
+ (std::rc::Rc<syrette::di_container::DIContainer>,),
+ #factory_interface
> -> syrette::interfaces::any_factory::AnyFactory
);
}
@@ -315,14 +320,17 @@ pub fn declare_default_factory(args_stream: TokenStream) -> TokenStream
quote! {
syrette::declare_interface!(
syrette::castable_factory::blocking::CastableFactory<
- (),
+ (std::rc::Rc<syrette::di_container::DIContainer>,),
#interface,
- > -> syrette::interfaces::factory::IFactory<(), #interface>
+ > -> syrette::interfaces::factory::IFactory<
+ (std::rc::Rc<syrette::di_container::DIContainer>,),
+ #interface
+ >
);
syrette::declare_interface!(
syrette::castable_factory::blocking::CastableFactory<
- (),
+ (std::rc::Rc<syrette::di_container::DIContainer>,),
#interface,
> -> syrette::interfaces::any_factory::AnyFactory
);