diff options
-rw-r--r-- | macros/src/injectable_impl.rs | 23 | ||||
-rw-r--r-- | src/dependency_trace.rs | 20 | ||||
-rw-r--r-- | src/lib.rs | 3 |
3 files changed, 29 insertions, 17 deletions
diff --git a/macros/src/injectable_impl.rs b/macros/src/injectable_impl.rs index b24749c..3bd7113 100644 --- a/macros/src/injectable_impl.rs +++ b/macros/src/injectable_impl.rs @@ -86,26 +86,15 @@ impl InjectableImpl if dependency_history.contains(&self_type_name) { dependency_history.push(self_type_name); - let dependency_trace = dependency_history - .iter() - .map(|dep| { - if dep == &self_type_name { - format!("\x1b[1m{}\x1b[22m", dep) - } else { - dep.to_string() - } - }) - .collect::<Vec<_>>() - .join(" -> "); - return Err( report!(ResolveError) - .attach_printable( - format!( - "Detected circular dependencies. {}", - dependency_trace.clone(), + .attach_printable(format!( + "Detected circular dependencies. {}", + syrette::dependency_trace::create_dependency_trace( + dependency_history.as_slice(), + self_type_name ) - ) + )) ); } diff --git a/src/dependency_trace.rs b/src/dependency_trace.rs new file mode 100644 index 0000000..d46b762 --- /dev/null +++ b/src/dependency_trace.rs @@ -0,0 +1,20 @@ +#![allow(clippy::module_name_repetitions)] + +#[must_use] +pub fn create_dependency_trace( + dependency_history: &[&'static str], + err_dependency: &'static str, +) -> String +{ + dependency_history + .iter() + .map(|dep| { + if dep == &err_dependency { + format!("\x1b[1m{}\x1b[22m", dep) + } else { + (*dep).to_string() + } + }) + .collect::<Vec<_>>() + .join(" -> ") +} @@ -20,6 +20,9 @@ pub use syrette_macros::*; pub mod castable_factory; #[doc(hidden)] +pub mod dependency_trace; + +#[doc(hidden)] pub mod libs; // Private |