Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Debug implementation of Handle #1116

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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