Auto merge of #32565 - tbu-:pr_cell_as_mut, r=alexcrichton
Add `as_mut` methods to the `std::cell` structs This is safe since the borrow checking ensures that we have the only mutable reference to the struct, thus we can safely borrow its interior.
This commit is contained in:
commit
b071c1feea
@ -232,6 +232,18 @@ impl<T:Copy> Cell<T> {
|
||||
pub fn as_unsafe_cell(&self) -> &UnsafeCell<T> {
|
||||
&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<T: ?Sized> RefCell<T> {
|
||||
pub unsafe fn as_unsafe_cell(&self) -> &UnsafeCell<T> {
|
||||
&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")]
|
||||
|
Loading…
x
Reference in New Issue
Block a user