From fdd7f824fd1244226ca86f525f8439744676688f Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 24 Sep 2022 17:31:16 +0200 Subject: feat: add bind async default factories to async DI container --- src/provider/async.rs | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'src/provider') diff --git a/src/provider/async.rs b/src/provider/async.rs index df96b27..c9a5273 100644 --- a/src/provider/async.rs +++ b/src/provider/async.rs @@ -26,6 +26,12 @@ pub enum AsyncProvidable dyn crate::interfaces::any_factory::AnyThreadsafeFactory, >, ), + #[cfg(feature = "factory")] + AsyncDefaultFactory( + crate::ptr::ThreadsafeFactoryPtr< + dyn crate::interfaces::any_factory::AnyThreadsafeFactory, + >, + ), } #[async_trait] @@ -150,13 +156,21 @@ where } } +#[derive(Clone, Copy)] +pub enum AsyncFactoryVariant +{ + Normal, + Default, + AsyncDefault, +} + #[cfg(feature = "factory")] pub struct AsyncFactoryProvider { factory: crate::ptr::ThreadsafeFactoryPtr< dyn crate::interfaces::any_factory::AnyThreadsafeFactory, >, - is_default_factory: bool, + variant: AsyncFactoryVariant, } #[cfg(feature = "factory")] @@ -166,13 +180,10 @@ impl AsyncFactoryProvider factory: crate::ptr::ThreadsafeFactoryPtr< dyn crate::interfaces::any_factory::AnyThreadsafeFactory, >, - is_default_factory: bool, + variant: AsyncFactoryVariant, ) -> Self { - Self { - factory, - is_default_factory, - } + Self { factory, variant } } } @@ -186,10 +197,14 @@ impl IAsyncProvider for AsyncFactoryProvider _dependency_history: Vec<&'static str>, ) -> Result { - Ok(if self.is_default_factory { - AsyncProvidable::DefaultFactory(self.factory.clone()) - } else { - AsyncProvidable::Factory(self.factory.clone()) + Ok(match self.variant { + AsyncFactoryVariant::Normal => AsyncProvidable::Factory(self.factory.clone()), + AsyncFactoryVariant::Default => { + AsyncProvidable::DefaultFactory(self.factory.clone()) + } + AsyncFactoryVariant::AsyncDefault => { + AsyncProvidable::AsyncDefaultFactory(self.factory.clone()) + } }) } @@ -206,7 +221,7 @@ impl Clone for AsyncFactoryProvider { Self { factory: self.factory.clone(), - is_default_factory: self.is_default_factory.clone(), + variant: self.variant, } } } -- cgit v1.2.3-18-g5258