diff options
author | HampusM <hampus@hampusmat.com> | 2024-09-16 00:26:40 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-09-16 00:26:40 +0200 |
commit | e2b38115ec695a6620cdf244fd7bad922262560d (patch) | |
tree | 1e104c71d816720b0c4c734b861d6a83467faccb /src/provider/blocking.rs | |
parent | d46181de1c19328ff8f3f6a12784cf14c53e9e71 (diff) |
feat: make to_*dynamic_value functions usable without nightly Rust
Diffstat (limited to 'src/provider/blocking.rs')
-rw-r--r-- | src/provider/blocking.rs | 37 |
1 files changed, 7 insertions, 30 deletions
diff --git a/src/provider/blocking.rs b/src/provider/blocking.rs index e7f113b..6b22ad0 100644 --- a/src/provider/blocking.rs +++ b/src/provider/blocking.rs @@ -1,5 +1,7 @@ use std::marker::PhantomData; +use std::rc::Rc; +use crate::castable_function::AnyCastableFunction; use crate::errors::injectable::InjectableError; use crate::interfaces::injectable::Injectable; use crate::ptr::{SingletonPtr, TransientPtr}; @@ -12,19 +14,15 @@ pub enum Providable<DIContainerType> { Transient(TransientPtr<dyn Injectable<DIContainerType>>), Singleton(SingletonPtr<dyn Injectable<DIContainerType>>), - #[cfg(feature = "factory")] - Function( - std::rc::Rc<dyn crate::castable_function::AnyCastableFunction>, - ProvidableFunctionKind, - ), + Function(Rc<dyn AnyCastableFunction>, ProvidableFunctionKind), } -#[cfg(feature = "factory")] #[derive(Debug, Clone, Copy)] pub enum ProvidableFunctionKind { - Instant, + #[cfg(feature = "factory")] UserCalled, + Instant, } #[cfg_attr(test, mockall::automock)] @@ -114,18 +112,16 @@ where } } -#[cfg(feature = "factory")] pub struct FunctionProvider { - function: std::rc::Rc<dyn crate::castable_function::AnyCastableFunction>, + function: Rc<dyn AnyCastableFunction>, providable_func_kind: ProvidableFunctionKind, } -#[cfg(feature = "factory")] impl FunctionProvider { pub fn new( - function: std::rc::Rc<dyn crate::castable_function::AnyCastableFunction>, + function: Rc<dyn AnyCastableFunction>, providable_func_kind: ProvidableFunctionKind, ) -> Self { @@ -136,7 +132,6 @@ impl FunctionProvider } } -#[cfg(feature = "factory")] impl<DIContainerType> IProvider<DIContainerType> for FunctionProvider { fn provide( @@ -201,7 +196,6 @@ mod tests } #[test] - #[cfg(feature = "factory")] fn function_provider_works() { use std::any::Any; @@ -220,11 +214,6 @@ mod tests } } - let user_called_func_provider = FunctionProvider::new( - Rc::new(FooFactory), - ProvidableFunctionKind::UserCalled, - ); - let instant_func_provider = FunctionProvider::new(Rc::new(FooFactory), ProvidableFunctionKind::Instant); @@ -232,18 +221,6 @@ mod tests assert!( matches!( - user_called_func_provider - .provide(&di_container, MockDependencyHistory::new()), - Ok(Providable::Function(_, ProvidableFunctionKind::UserCalled)) - ), - concat!( - "The provided type is not a Providable::Function of kind ", - "ProvidableFunctionKind::UserCalled" - ) - ); - - assert!( - matches!( instant_func_provider .provide(&di_container, MockDependencyHistory::new()), Ok(Providable::Function(_, ProvidableFunctionKind::Instant)) |