Skip to content

Commit

Permalink
Merge pull request #1116 from hannobraun/handle
Browse files Browse the repository at this point in the history
Improve `Debug` implementation of `Handle`
  • Loading branch information
hannobraun authored Sep 20, 2022
2 parents f12bc32 + cb0b4ca commit 895ebfa
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions crates/fj-kernel/src/stores/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -222,7 +225,18 @@ where

impl<T> fmt::Debug for Handle<T> {
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::<T>();
match type_name.rsplit_once("::") {
Some((_, name)) => name,
None => type_name,
}
};
let id = self.id();

write!(f, "{name} @ {id:#x}")?;

Ok(())
}
}

Expand Down

0 comments on commit 895ebfa

Please sign in to comment.