Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
Implement Debug for Boxed/Shared via Formatter::debug_struct()/debug_…
Browse files Browse the repository at this point in the history
…tuple()

This improves formatting of the output
  • Loading branch information
sdroege committed Aug 17, 2018
1 parent d0cc9ca commit aaf1430
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,15 @@ impl<T> fmt::Debug for AnyBox<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::AnyBox::*;
match *self {
Native(ref b) => write!(f, "Native({:?})", &**b as *const T),
ForeignOwned(ptr) => write!(f, "ForeignOwned({:?})", ptr),
ForeignBorrowed(ptr) => write!(f, "ForeignBorrowed({:?})", ptr),
Native(ref b) => f.debug_tuple("Native")
.field(&(&**b as *const T))
.finish(),
ForeignOwned(ptr) => f.debug_tuple("ForeignOwned")
.field(&ptr)
.finish(),
ForeignBorrowed(ptr) => f.debug_tuple("ForeignBorrowed")
.field(&ptr)
.finish(),
}
}
}
Expand Down Expand Up @@ -398,7 +404,10 @@ impl<T: 'static, MM: BoxedMemoryManager<T>> Drop for Boxed<T, MM> {

impl<T: 'static, MM: BoxedMemoryManager<T>> fmt::Debug for Boxed<T, MM> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Boxed {{ inner: {:?} }}", self.inner)
f.debug_struct("Boxed")
.field("inner", &self.inner)
.finish()
}
}

impl<T, MM: BoxedMemoryManager<T>> PartialOrd for Boxed<T, MM> {
Expand Down
5 changes: 4 additions & 1 deletion src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,10 @@ impl<T, MM: SharedMemoryManager<T>> Clone for Shared<T, MM> {

impl<T, MM: SharedMemoryManager<T>> fmt::Debug for Shared<T, MM> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Shared {{ inner: {:?}, borrowed: {} }}", self.inner, self.borrowed)
f.debug_struct("Shared")
.field("inner", &self.inner)
.field("borrowed", &self.borrowed)
.finish()
}
}

Expand Down

0 comments on commit aaf1430

Please sign in to comment.