From e2b38115ec695a6620cdf244fd7bad922262560d Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 16 Sep 2024 00:26:40 +0200 Subject: feat: make to_*dynamic_value functions usable without nightly Rust --- src/provider/blocking.rs | 37 +++++++------------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) (limited to 'src/provider/blocking.rs') 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 { Transient(TransientPtr>), Singleton(SingletonPtr>), - #[cfg(feature = "factory")] - Function( - std::rc::Rc, - ProvidableFunctionKind, - ), + Function(Rc, 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, + function: Rc, providable_func_kind: ProvidableFunctionKind, } -#[cfg(feature = "factory")] impl FunctionProvider { pub fn new( - function: std::rc::Rc, + function: Rc, providable_func_kind: ProvidableFunctionKind, ) -> Self { @@ -136,7 +132,6 @@ impl FunctionProvider } } -#[cfg(feature = "factory")] impl IProvider for FunctionProvider { fn provide( @@ -201,7 +196,6 @@ mod tests } #[test] - #[cfg(feature = "factory")] fn function_provider_works() { use std::any::Any; @@ -220,28 +214,11 @@ 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); let di_container = MockDIContainer::new(); - 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 -- cgit v1.2.3-18-g5258