diff options
author | HampusM <hampus@hampusmat.com> | 2023-10-04 12:51:06 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-10-04 12:52:22 +0200 |
commit | 0f2756536e8fc311119da2af5b4dcc33f41bec6e (patch) | |
tree | 0964efe0eaf855017c67fae52da8672a47becc65 /src/di_container/blocking | |
parent | c936439bfac9e35958f685a52abb51d781e70a7c (diff) |
refactor!: remove factory & declare_default_factory macros
BREAKING CHANGE: The factory and the declare_default_factory macros have been removed. They are no longer needed to use factories
Diffstat (limited to 'src/di_container/blocking')
-rw-r--r-- | src/di_container/blocking/binding/builder.rs | 18 | ||||
-rw-r--r-- | src/di_container/blocking/mod.rs | 30 |
2 files changed, 16 insertions, 32 deletions
diff --git a/src/di_container/blocking/binding/builder.rs b/src/di_container/blocking/binding/builder.rs index f322809..9f7f6f9 100644 --- a/src/di_container/blocking/binding/builder.rs +++ b/src/di_container/blocking/binding/builder.rs @@ -119,7 +119,7 @@ where /// ``` /// # use std::error::Error; /// # - /// # use syrette::{DIContainer, factory}; + /// # use syrette::DIContainer; /// # use syrette::ptr::TransientPtr; /// # /// # trait ICustomerID {} @@ -140,10 +140,8 @@ where /// # /// # impl ICustomer for Customer {} /// # - /// # #[factory] /// # type ICustomerFactory = dyn Fn(String, u32) -> TransientPtr<dyn ICustomer>; /// # - /// # #[factory] /// # type ICustomerIDFactory = dyn Fn(u32) -> TransientPtr<dyn ICustomerID>; /// # /// # fn main() -> Result<(), Box<dyn Error>> @@ -183,7 +181,7 @@ where Interface: Fn<Args, Output = crate::ptr::TransientPtr<Return>>, Func: Fn(&DIContainer) -> Box<Interface>, { - use crate::private::castable_factory::CastableFactory; + use crate::castable_factory::CastableFactory; if self .di_container @@ -218,7 +216,7 @@ where /// ``` /// # use std::error::Error; /// # - /// # use syrette::{DIContainer, factory}; + /// # use syrette::DIContainer; /// # use syrette::ptr::TransientPtr; /// # /// # trait IBuffer {} @@ -271,7 +269,7 @@ where dyn Fn<(), Output = crate::ptr::TransientPtr<Return>>, >, { - use crate::private::castable_factory::CastableFactory; + use crate::castable_factory::CastableFactory; if self .di_container @@ -335,11 +333,8 @@ mod tests #[cfg(feature = "factory")] fn can_bind_to_factory() { - use crate as syrette; - use crate::factory; use crate::ptr::TransientPtr; - #[factory] type IUserManagerFactory = dyn Fn(i32, String) -> TransientPtr<dyn subjects::IUserManager>; @@ -378,13 +373,8 @@ mod tests #[cfg(feature = "factory")] fn can_bind_to_default_factory() { - use syrette_macros::declare_default_factory; - - use crate as syrette; use crate::ptr::TransientPtr; - declare_default_factory!(dyn subjects::IUserManager); - let mut mock_di_container = MockDIContainer::new(); mock_di_container diff --git a/src/di_container/blocking/mod.rs b/src/di_container/blocking/mod.rs index 65e697e..d9efe94 100644 --- a/src/di_container/blocking/mod.rs +++ b/src/di_container/blocking/mod.rs @@ -285,11 +285,12 @@ impl DIContainer )), #[cfg(feature = "factory")] Providable::Factory(factory_binding) => { - use crate::private::factory::IFactory; + use crate::castable_factory::CastableFactory; let factory = factory_binding - .cast::<dyn IFactory<Interface, Self>>() - .map_err(|_| DIContainerError::CastFailed { + .as_any() + .downcast_ref::<CastableFactory<Interface, Self>>() + .ok_or_else(|| DIContainerError::CastFailed { interface: type_name::<Interface>(), binding_kind: "factory", })?; @@ -298,17 +299,16 @@ impl DIContainer } #[cfg(feature = "factory")] Providable::DefaultFactory(factory_binding) => { - use crate::private::factory::IFactory; + use crate::castable_factory::CastableFactory; use crate::ptr::TransientPtr; - type DefaultFactoryFn<Interface> = dyn IFactory< - dyn Fn<(), Output = TransientPtr<Interface>>, - DIContainer, - >; + type DefaultFactoryFn<Interface> = + CastableFactory<dyn Fn() -> TransientPtr<Interface>, DIContainer>; let default_factory = factory_binding - .cast::<DefaultFactoryFn<Interface>>() - .map_err(|_| DIContainerError::CastFailed { + .as_any() + .downcast_ref::<DefaultFactoryFn<Interface>>() + .ok_or_else(|| DIContainerError::CastFailed { interface: type_name::<Interface>(), binding_kind: "default factory", })?; @@ -517,7 +517,7 @@ mod tests #[cfg(feature = "factory")] fn can_get_factory() { - use crate::private::castable_factory::CastableFactory; + use crate::castable_factory::CastableFactory; use crate::ptr::FactoryPtr; trait IUserManager @@ -556,9 +556,6 @@ mod tests } } - use crate as syrette; - - #[crate::factory] type IUserManagerFactory = dyn Fn(Vec<i128>) -> TransientPtr<dyn IUserManager>; let mut di_container = DIContainer::new(); @@ -595,7 +592,7 @@ mod tests #[cfg(feature = "factory")] fn can_get_factory_named() { - use crate::private::castable_factory::CastableFactory; + use crate::castable_factory::CastableFactory; use crate::ptr::FactoryPtr; trait IUserManager @@ -634,9 +631,6 @@ mod tests } } - use crate as syrette; - - #[crate::factory] type IUserManagerFactory = dyn Fn(Vec<i128>) -> TransientPtr<dyn IUserManager>; let mut di_container = DIContainer::new(); |