aboutsummaryrefslogtreecommitdiff
path: root/macros
diff options
context:
space:
mode:
Diffstat (limited to 'macros')
-rw-r--r--macros/Cargo.toml1
-rw-r--r--macros/src/injectable_impl.rs40
2 files changed, 25 insertions, 16 deletions
diff --git a/macros/Cargo.toml b/macros/Cargo.toml
index 36cc8eb..73f583d 100644
--- a/macros/Cargo.toml
+++ b/macros/Cargo.toml
@@ -16,6 +16,7 @@ all-features = true
[features]
factory = []
+prevent-circular = []
[dependencies]
syn = { version = "1.0.96", features = ["full"] }
diff --git a/macros/src/injectable_impl.rs b/macros/src/injectable_impl.rs
index 3bd7113..29e0094 100644
--- a/macros/src/injectable_impl.rs
+++ b/macros/src/injectable_impl.rs
@@ -66,6 +66,29 @@ impl InjectableImpl
}
};
+ let maybe_prevent_circular_deps = if cfg!(feature = "prevent-circular") {
+ quote! {
+ if dependency_history.contains(&self_type_name) {
+ dependency_history.push(self_type_name);
+
+ return Err(
+ report!(ResolveError)
+ .attach_printable(format!(
+ "Detected circular dependencies. {}",
+ syrette::dependency_trace::create_dependency_trace(
+ dependency_history.as_slice(),
+ self_type_name
+ )
+ ))
+ );
+ }
+
+ dependency_history.push(self_type_name);
+ }
+ } else {
+ quote! {}
+ };
+
quote! {
#original_impl
@@ -83,22 +106,7 @@ impl InjectableImpl
let self_type_name = std::any::type_name::<#self_type>();
- if dependency_history.contains(&self_type_name) {
- dependency_history.push(self_type_name);
-
- return Err(
- report!(ResolveError)
- .attach_printable(format!(
- "Detected circular dependencies. {}",
- syrette::dependency_trace::create_dependency_trace(
- dependency_history.as_slice(),
- self_type_name
- )
- ))
- );
- }
-
- dependency_history.push(self_type_name);
+ #maybe_prevent_circular_deps
return Ok(syrette::ptr::TransientPtr::new(Self::new(
#(#get_dependencies