From 0f2756536e8fc311119da2af5b4dcc33f41bec6e Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 4 Oct 2023 12:51:06 +0200 Subject: 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 --- src/di_container/blocking/mod.rs | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'src/di_container/blocking/mod.rs') 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::>() - .map_err(|_| DIContainerError::CastFailed { + .as_any() + .downcast_ref::>() + .ok_or_else(|| DIContainerError::CastFailed { interface: type_name::(), 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 = dyn IFactory< - dyn Fn<(), Output = TransientPtr>, - DIContainer, - >; + type DefaultFactoryFn = + CastableFactory TransientPtr, DIContainer>; let default_factory = factory_binding - .cast::>() - .map_err(|_| DIContainerError::CastFailed { + .as_any() + .downcast_ref::>() + .ok_or_else(|| DIContainerError::CastFailed { interface: type_name::(), 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) -> TransientPtr; 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) -> TransientPtr; let mut di_container = DIContainer::new(); -- cgit v1.2.3-18-g5258