From f35b3d29d8ed521f69522aa0fda594f277c72b5c Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 2 Aug 2022 17:30:21 +0200 Subject: refactor: move creating a dependency trace to it's own function --- src/dependency_trace.rs | 20 ++++++++++++++++++++ src/lib.rs | 3 +++ 2 files changed, 23 insertions(+) create mode 100644 src/dependency_trace.rs (limited to 'src') 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::>() + .join(" -> ") +} diff --git a/src/lib.rs b/src/lib.rs index 4d1ce78..a03675b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,6 +19,9 @@ pub use syrette_macros::*; #[doc(hidden)] pub mod castable_factory; +#[doc(hidden)] +pub mod dependency_trace; + #[doc(hidden)] pub mod libs; -- cgit v1.2.3-18-g5258