From aa548ded39c7ba1927019c748c359523b21d59e8 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 29 Oct 2022 14:38:51 +0200 Subject: refactor!: add dependency history type BREAKING CHANGE: Binding builders & configurators now take dependency history type arguments, the DetectedCircular variant of InjectableError now contains a dependency history field & the injectable traits take dependency history instead of a Vec --- macros/src/injectable/implementation.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'macros/src') diff --git a/macros/src/injectable/implementation.rs b/macros/src/injectable/implementation.rs index 6cde446..cfbc620 100644 --- a/macros/src/injectable/implementation.rs +++ b/macros/src/injectable/implementation.rs @@ -101,19 +101,17 @@ impl InjectableImpl ) -> proc_macro2::TokenStream { quote! { - if #dependency_history_var.contains(&self_type_name) { - #dependency_history_var.push(self_type_name); + use syrette::dependency_history::IDependencyHistory; - let dependency_trace = - syrette::dependency_trace::create_dependency_trace( - #dependency_history_var.as_slice(), - self_type_name - ); + if #dependency_history_var.contains::() { + #dependency_history_var.push::(); - return Err(InjectableError::DetectedCircular {dependency_trace }); + return Err(InjectableError::DetectedCircular { + dependency_history: #dependency_history_var + }); } - #dependency_history_var.push(self_type_name); + #dependency_history_var.push::(); } } @@ -133,14 +131,15 @@ impl InjectableImpl quote! { #maybe_doc_hidden impl #generics syrette::interfaces::async_injectable::AsyncInjectable< - syrette::di_container::asynchronous::AsyncDIContainer + syrette::di_container::asynchronous::AsyncDIContainer, + syrette::dependency_history::DependencyHistory > for #self_type { fn resolve<'di_container, 'fut>( #di_container_var: &'di_container std::sync::Arc< syrette::di_container::asynchronous::AsyncDIContainer >, - mut #dependency_history_var: Vec<&'static str>, + mut #dependency_history_var: syrette::dependency_history::DependencyHistory ) -> syrette::future::BoxFuture< 'fut, Result< @@ -187,14 +186,15 @@ impl InjectableImpl quote! { #maybe_doc_hidden impl #generics syrette::interfaces::injectable::Injectable< - syrette::di_container::blocking::DIContainer + syrette::di_container::blocking::DIContainer, + syrette::dependency_history::DependencyHistory > for #self_type { fn resolve( #di_container_var: &std::rc::Rc< syrette::di_container::blocking::DIContainer >, - mut #dependency_history_var: Vec<&'static str>, + mut #dependency_history_var: syrette::dependency_history::DependencyHistory ) -> Result< syrette::ptr::TransientPtr, syrette::errors::injectable::InjectableError> -- cgit v1.2.3-18-g5258