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/di_container/asynchronous.rs | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'src/di_container/asynchronous.rs') diff --git a/src/di_container/asynchronous.rs b/src/di_container/asynchronous.rs index a338c0a..6cb54f3 100644 --- a/src/di_container/asynchronous.rs +++ b/src/di_container/asynchronous.rs @@ -51,15 +51,17 @@ //! ``` use std::any::type_name; +use crate::castable_function::threadsafe::ThreadsafeCastableFunction; use crate::di_container::asynchronous::binding::builder::AsyncBindingBuilder; use crate::di_container::binding_storage::DIContainerBindingStorage; use crate::di_container::BindingOptions; use crate::errors::async_di_container::AsyncDIContainerError; +use crate::future::BoxFuture; use crate::private::cast::arc::CastArc; use crate::private::cast::boxed::CastBox; use crate::private::cast::error::CastError; -use crate::provider::r#async::{AsyncProvidable, IAsyncProvider}; -use crate::ptr::SomePtr; +use crate::provider::r#async::{AsyncProvidable, IAsyncProvider, ProvidableFunctionKind}; +use crate::ptr::{SomePtr, TransientPtr}; use crate::util::use_double; use_double!(crate::dependency_history::DependencyHistory); @@ -347,12 +349,7 @@ impl AsyncDIContainer )) } #[cfg(feature = "factory")] - AsyncProvidable::Function( - func_bound, - crate::provider::r#async::ProvidableFunctionKind::UserCalled, - ) => { - use crate::castable_function::threadsafe::ThreadsafeCastableFunction; - + AsyncProvidable::Function(func_bound, ProvidableFunctionKind::UserCalled) => { let factory = func_bound .as_any() .downcast_ref::>() @@ -363,14 +360,7 @@ impl AsyncDIContainer Ok(SomePtr::ThreadsafeFactory(factory.call(self).into())) } - #[cfg(feature = "factory")] - AsyncProvidable::Function( - func_bound, - crate::provider::r#async::ProvidableFunctionKind::Instant, - ) => { - use crate::castable_function::threadsafe::ThreadsafeCastableFunction; - use crate::ptr::TransientPtr; - + AsyncProvidable::Function(func_bound, ProvidableFunctionKind::Instant) => { type Func = ThreadsafeCastableFunction< dyn Fn() -> TransientPtr + Send + Sync, AsyncDIContainer, @@ -386,19 +376,12 @@ impl AsyncDIContainer Ok(SomePtr::Transient(dynamic_val_func.call(self)())) } - #[cfg(feature = "factory")] AsyncProvidable::Function( func_bound, - crate::provider::r#async::ProvidableFunctionKind::AsyncInstant, + ProvidableFunctionKind::AsyncInstant, ) => { - use crate::castable_function::threadsafe::ThreadsafeCastableFunction; - use crate::future::BoxFuture; - use crate::ptr::TransientPtr; - type Func = ThreadsafeCastableFunction< - dyn Fn<(), Output = BoxFuture<'static, TransientPtr>> - + Send - + Sync, + dyn Fn() -> BoxFuture<'static, TransientPtr> + Send + Sync, AsyncDIContainer, >; -- cgit v1.2.3-18-g5258