From cb0b4ca59344de817868a7e5662fb0f39364fd1c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 20 Sep 2022 15:14:27 +0200 Subject: [PATCH] Improve `Debug` implementation of `Handle` --- crates/fj-kernel/src/stores/store.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/stores/store.rs b/crates/fj-kernel/src/stores/store.rs index 6e8c4b9e9..851637ea5 100644 --- a/crates/fj-kernel/src/stores/store.rs +++ b/crates/fj-kernel/src/stores/store.rs @@ -21,7 +21,10 @@ //! //! But in any case, this was fun to write, and not that much work. -use std::{fmt, hash::Hash, iter, marker::PhantomData, ops::Deref, sync::Arc}; +use std::{ + any::type_name, fmt, hash::Hash, iter, marker::PhantomData, ops::Deref, + sync::Arc, +}; use parking_lot::RwLock; @@ -222,7 +225,18 @@ where impl fmt::Debug for Handle { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_struct("Handle").field("id", &self.id()).finish() + let name = { + let type_name = type_name::(); + match type_name.rsplit_once("::") { + Some((_, name)) => name, + None => type_name, + } + }; + let id = self.id(); + + write!(f, "{name} @ {id:#x}")?; + + Ok(()) } }