Skip to content

Add as_mut methods to the std::cell structs #32565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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")]
Expand Down