Skip to content

Commit

Permalink
Import Debug implementations for RefCell and friends
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Aug 31, 2016
1 parent c87180a commit c50e6ad
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions components/style/refcell.rs
Expand Up @@ -633,3 +633,35 @@ impl<'b, T: ?Sized> DerefMut for RefMut<'b, T> {
self.value
}
}


// Imported from src/libcore/fmt/mod.rs

impl<T: ?Sized + Debug> Debug for RefCell<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.borrow_state() {
BorrowState::Unused | BorrowState::Reading => {
f.debug_struct("RefCell")
.field("value", &self.borrow())
.finish()
}
BorrowState::Writing => {
f.debug_struct("RefCell")
.field("value", &"<borrowed>")
.finish()
}
}
}
}

impl<'b, T: ?Sized + Debug> Debug for Ref<'b, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Debug::fmt(&**self, f)
}
}

impl<'b, T: ?Sized + Debug> Debug for RefMut<'b, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Debug::fmt(&*(self.deref()), f)
}
}

0 comments on commit c50e6ad

Please sign in to comment.