diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 257027dad5ed2..19c778b023490 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -232,6 +232,18 @@ impl Cell { pub fn as_unsafe_cell(&self) -> &UnsafeCell { &self.value } + + /// Returns a mutable reference to the underlying data. + /// + /// This call borrows `Cell` mutably (at compile-time) which guarantees + /// that we possess the only reference. + #[inline] + #[unstable(feature = "cell_get_mut", issue = "33444")] + pub fn get_mut(&mut self) -> &mut T { + unsafe { + &mut *self.value.get() + } + } } #[stable(feature = "rust1", since = "1.0.0")] @@ -455,6 +467,18 @@ impl RefCell { pub unsafe fn as_unsafe_cell(&self) -> &UnsafeCell { &self.value } + + /// Returns a mutable reference to the underlying data. + /// + /// This call borrows `RefCell` mutably (at compile-time) so there is no + /// need for dynamic checks. + #[inline] + #[unstable(feature = "cell_get_mut", issue="33444")] + pub fn get_mut(&mut self) -> &mut T { + unsafe { + &mut *self.value.get() + } + } } #[stable(feature = "rust1", since = "1.0.0")]