Import Debug implementations for RefCell and friends

This commit is contained in:
Simon Sapin 2016-08-30 23:37:29 +02:00
parent c87180a2fb
commit c50e6add4a

View file

@ -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)
}
}