diff options
-rw-r--r-- | macros/src/injectable/implementation.rs | 36 | ||||
-rw-r--r-- | src/interfaces/async_injectable.rs | 13 | ||||
-rw-r--r-- | src/libs/mod.rs | 2 |
3 files changed, 29 insertions, 22 deletions
diff --git a/macros/src/injectable/implementation.rs b/macros/src/injectable/implementation.rs index a84e798..82cbe16 100644 --- a/macros/src/injectable/implementation.rs +++ b/macros/src/injectable/implementation.rs @@ -87,27 +87,37 @@ impl InjectableImpl quote! { #maybe_doc_hidden - #[syrette::libs::async_trait::async_trait] impl #generics syrette::interfaces::async_injectable::AsyncInjectable for #self_type { - async fn resolve( - #di_container_var: &std::sync::Arc<syrette::async_di_container::AsyncDIContainer>, + fn resolve<'di_container, 'fut>( + #di_container_var: &'di_container std::sync::Arc< + syrette::async_di_container::AsyncDIContainer + >, mut #dependency_history_var: Vec<&'static str>, - ) -> Result< - syrette::ptr::TransientPtr<Self>, - syrette::errors::injectable::InjectableError> + ) -> syrette::future::BoxFuture< + 'fut, + Result< + syrette::ptr::TransientPtr<Self>, + syrette::errors::injectable::InjectableError + > + > + where + Self: Sized + 'fut, + 'di_container: 'fut { - use std::any::type_name; + Box::pin(async move { + use std::any::type_name; - use syrette::errors::injectable::InjectableError; + use syrette::errors::injectable::InjectableError; - let self_type_name = type_name::<#self_type>(); + let self_type_name = type_name::<#self_type>(); - #maybe_prevent_circular_deps + #maybe_prevent_circular_deps - return Ok(syrette::ptr::TransientPtr::new(Self::new( - #(#async_get_dep_method_calls),* - ))); + Ok(syrette::ptr::TransientPtr::new(Self::new( + #(#async_get_dep_method_calls),* + ))) + }) } } diff --git a/src/interfaces/async_injectable.rs b/src/interfaces/async_injectable.rs index fb5452b..07a21aa 100644 --- a/src/interfaces/async_injectable.rs +++ b/src/interfaces/async_injectable.rs @@ -4,27 +4,26 @@ use std::fmt::Debug; use std::sync::Arc; -use async_trait::async_trait; - use crate::async_di_container::AsyncDIContainer; use crate::errors::injectable::InjectableError; +use crate::future::BoxFuture; use crate::libs::intertrait::CastFromSync; use crate::ptr::TransientPtr; /// Interface for structs that can be injected into or be injected to. -#[async_trait] pub trait AsyncInjectable: CastFromSync { /// Resolves the dependencies of the injectable. /// /// # Errors /// Will return `Err` if resolving the dependencies fails. - async fn resolve( - di_container: &Arc<AsyncDIContainer>, + fn resolve<'di_container, 'fut>( + di_container: &'di_container Arc<AsyncDIContainer>, dependency_history: Vec<&'static str>, - ) -> Result<TransientPtr<Self>, InjectableError> + ) -> BoxFuture<'fut, Result<TransientPtr<Self>, InjectableError>> where - Self: Sized; + Self: Sized + 'fut, + 'di_container: 'fut; } impl Debug for dyn AsyncInjectable diff --git a/src/libs/mod.rs b/src/libs/mod.rs index b1c7a74..8d5583d 100644 --- a/src/libs/mod.rs +++ b/src/libs/mod.rs @@ -1,5 +1,3 @@ pub mod intertrait; -#[cfg(feature = "async")] -pub extern crate async_trait; pub extern crate linkme; |