Rollup merge of #46517 - notriddle:patch-2, r=BurntSushi

Stablize RefCell::{replace, swap}

RefCell::replace_with is not stablized in this PR, since it wasn't part of the RFC.

CC #43570
This commit is contained in:
kennytm 2017-12-20 21:21:51 +08:00 committed by GitHub
commit c3241b504f

View file

@ -584,7 +584,6 @@ impl<T> RefCell<T> {
/// # Examples
///
/// ```
/// #![feature(refcell_replace_swap)]
/// use std::cell::RefCell;
/// let cell = RefCell::new(5);
/// let old_value = cell.replace(6);
@ -592,7 +591,7 @@ impl<T> RefCell<T> {
/// assert_eq!(cell, RefCell::new(6));
/// ```
#[inline]
#[unstable(feature = "refcell_replace_swap", issue="43570")]
#[stable(feature = "refcell_replace", since="1.24.0")]
pub fn replace(&self, t: T) -> T {
mem::replace(&mut *self.borrow_mut(), t)
}
@ -636,7 +635,6 @@ impl<T> RefCell<T> {
/// # Examples
///
/// ```
/// #![feature(refcell_replace_swap)]
/// use std::cell::RefCell;
/// let c = RefCell::new(5);
/// let d = RefCell::new(6);
@ -645,7 +643,7 @@ impl<T> RefCell<T> {
/// assert_eq!(d, RefCell::new(5));
/// ```
#[inline]
#[unstable(feature = "refcell_replace_swap", issue="43570")]
#[stable(feature = "refcell_swap", since="1.24.0")]
pub fn swap(&self, other: &Self) {
mem::swap(&mut *self.borrow_mut(), &mut *other.borrow_mut())
}