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/provider | |
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/provider')
-rw-r--r-- | src/provider/async.rs | 31 | ||||
-rw-r--r-- | src/provider/blocking.rs | 20 |
2 files changed, 31 insertions, 20 deletions
diff --git a/src/provider/async.rs b/src/provider/async.rs index a3db57e..3875363 100644 --- a/src/provider/async.rs +++ b/src/provider/async.rs @@ -16,21 +16,15 @@ pub enum AsyncProvidable<DIContainerT> Singleton(ThreadsafeSingletonPtr<dyn AsyncInjectable<DIContainerT>>), #[cfg(feature = "factory")] Factory( - crate::ptr::ThreadsafeFactoryPtr< - dyn crate::private::any_factory::AnyThreadsafeFactory, - >, + crate::ptr::ThreadsafeFactoryPtr<dyn crate::any_factory::AnyThreadsafeFactory>, ), #[cfg(feature = "factory")] DefaultFactory( - crate::ptr::ThreadsafeFactoryPtr< - dyn crate::private::any_factory::AnyThreadsafeFactory, - >, + crate::ptr::ThreadsafeFactoryPtr<dyn crate::any_factory::AnyThreadsafeFactory>, ), #[cfg(feature = "factory")] AsyncDefaultFactory( - crate::ptr::ThreadsafeFactoryPtr< - dyn crate::private::any_factory::AnyThreadsafeFactory, - >, + crate::ptr::ThreadsafeFactoryPtr<dyn crate::any_factory::AnyThreadsafeFactory>, ), } @@ -188,9 +182,8 @@ pub enum AsyncFactoryVariant #[cfg(feature = "factory")] pub struct AsyncFactoryProvider { - factory: crate::ptr::ThreadsafeFactoryPtr< - dyn crate::private::any_factory::AnyThreadsafeFactory, - >, + factory: + crate::ptr::ThreadsafeFactoryPtr<dyn crate::any_factory::AnyThreadsafeFactory>, variant: AsyncFactoryVariant, } @@ -199,7 +192,7 @@ impl AsyncFactoryProvider { pub fn new( factory: crate::ptr::ThreadsafeFactoryPtr< - dyn crate::private::any_factory::AnyThreadsafeFactory, + dyn crate::any_factory::AnyThreadsafeFactory, >, variant: AsyncFactoryVariant, ) -> Self @@ -307,12 +300,22 @@ mod tests #[cfg(feature = "factory")] async fn async_factory_provider_works() { - use crate::private::any_factory::AnyThreadsafeFactory; + use std::any::Any; + + use crate::any_factory::{AnyFactory, AnyThreadsafeFactory}; use crate::ptr::ThreadsafeFactoryPtr; #[derive(Debug)] struct FooFactory; + impl AnyFactory for FooFactory + { + fn as_any(&self) -> &dyn Any + { + self + } + } + impl AnyThreadsafeFactory for FooFactory {} let factory_provider = AsyncFactoryProvider::new( diff --git a/src/provider/blocking.rs b/src/provider/blocking.rs index 5710a65..bde3be5 100644 --- a/src/provider/blocking.rs +++ b/src/provider/blocking.rs @@ -13,9 +13,9 @@ pub enum Providable<DIContainerType> Transient(TransientPtr<dyn Injectable<DIContainerType>>), Singleton(SingletonPtr<dyn Injectable<DIContainerType>>), #[cfg(feature = "factory")] - Factory(crate::ptr::FactoryPtr<dyn crate::private::any_factory::AnyFactory>), + Factory(crate::ptr::FactoryPtr<dyn crate::any_factory::AnyFactory>), #[cfg(feature = "factory")] - DefaultFactory(crate::ptr::FactoryPtr<dyn crate::private::any_factory::AnyFactory>), + DefaultFactory(crate::ptr::FactoryPtr<dyn crate::any_factory::AnyFactory>), } #[cfg_attr(test, mockall::automock)] @@ -108,7 +108,7 @@ where #[cfg(feature = "factory")] pub struct FactoryProvider { - factory: crate::ptr::FactoryPtr<dyn crate::private::any_factory::AnyFactory>, + factory: crate::ptr::FactoryPtr<dyn crate::any_factory::AnyFactory>, is_default_factory: bool, } @@ -116,7 +116,7 @@ pub struct FactoryProvider impl FactoryProvider { pub fn new( - factory: crate::ptr::FactoryPtr<dyn crate::private::any_factory::AnyFactory>, + factory: crate::ptr::FactoryPtr<dyn crate::any_factory::AnyFactory>, is_default_factory: bool, ) -> Self { @@ -196,13 +196,21 @@ mod tests #[cfg(feature = "factory")] fn factory_provider_works() { - use crate::private::any_factory::AnyFactory; + use std::any::Any; + + use crate::any_factory::AnyFactory; use crate::ptr::FactoryPtr; #[derive(Debug)] struct FooFactory; - impl AnyFactory for FooFactory {} + impl AnyFactory for FooFactory + { + fn as_any(&self) -> &dyn Any + { + self + } + } let factory_provider = FactoryProvider::new(FactoryPtr::new(FooFactory), false); let default_factory_provider = |