doc: a more complete explanation, and a better example

This commit is contained in:
Tshepang Lekhonkhobe 2017-06-08 22:46:11 +02:00
parent ae3d3878ef
commit c288864ed0
1 changed files with 5 additions and 5 deletions

View File

@ -391,17 +391,17 @@ impl<T> Cell<T> {
}
}
/// Replaces the contained value.
/// Replaces the contained value, and returns it.
///
/// # Examples
///
/// ```
/// use std::cell::Cell;
///
/// let c = Cell::new(5);
/// let old = c.replace(10);
///
/// assert_eq!(5, old);
/// let cell = Cell::new(5);
/// assert_eq!(cell.get(), 5);
/// assert_eq!(cell.replace(10), 5);
/// assert_eq!(cell.get(), 10);
/// ```
#[stable(feature = "move_cell", since = "1.17.0")]
pub fn replace(&self, val: T) -> T {