aboutsummaryrefslogtreecommitdiff
path: root/src/castable_factory/blocking.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-10-25 21:51:46 +0200
committerHampusM <hampus@hampusmat.com>2022-10-25 21:51:46 +0200
commitdba27b4402648b6a9272cda681ab8caaeb5d279d (patch)
treec7044883595aa706cab508175bcb99e9f4bfc492 /src/castable_factory/blocking.rs
parent8c6431fd834337be7f6b88e3c8a29c6a17e0b9cf (diff)
refactor: add Debug implementations for castable factories
Diffstat (limited to 'src/castable_factory/blocking.rs')
-rw-r--r--src/castable_factory/blocking.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/castable_factory/blocking.rs b/src/castable_factory/blocking.rs
index 9ef9864..48f426d 100644
--- a/src/castable_factory/blocking.rs
+++ b/src/castable_factory/blocking.rs
@@ -1,3 +1,6 @@
+use std::any::type_name;
+use std::fmt::Debug;
+
use crate::interfaces::any_factory::AnyFactory;
use crate::interfaces::factory::IFactory;
use crate::ptr::TransientPtr;
@@ -73,6 +76,36 @@ where
{
}
+impl<Args, ReturnInterface> Debug for CastableFactory<Args, ReturnInterface>
+where
+ Args: 'static,
+ ReturnInterface: 'static + ?Sized,
+{
+ #[cfg(not(tarpaulin_include))]
+ fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
+ {
+ let mut args = type_name::<Args>();
+
+ if args.len() < 2 {
+ return Err(std::fmt::Error::default());
+ }
+
+ args = args
+ .get(1..args.len() - 1)
+ .map_or_else(|| Err(std::fmt::Error::default()), Ok)?;
+
+ if args.ends_with(',') {
+ args = args
+ .get(..args.len() - 1)
+ .map_or_else(|| Err(std::fmt::Error), Ok)?;
+ }
+
+ let ret = type_name::<TransientPtr<ReturnInterface>>();
+
+ formatter.write_fmt(format_args!("CastableFactory ({}) -> {}", args, ret))
+ }
+}
+
#[cfg(test)]
mod tests
{