Skip to content

Commit c288864

Browse files
committed
doc: a more complete explanation, and a better example
1 parent ae3d387 commit c288864

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/libcore/cell.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -391,17 +391,17 @@ impl<T> Cell<T> {
391391
}
392392
}
393393

394-
/// Replaces the contained value.
394+
/// Replaces the contained value, and returns it.
395395
///
396396
/// # Examples
397397
///
398398
/// ```
399399
/// use std::cell::Cell;
400400
///
401-
/// let c = Cell::new(5);
402-
/// let old = c.replace(10);
403-
///
404-
/// assert_eq!(5, old);
401+
/// let cell = Cell::new(5);
402+
/// assert_eq!(cell.get(), 5);
403+
/// assert_eq!(cell.replace(10), 5);
404+
/// assert_eq!(cell.get(), 10);
405405
/// ```
406406
#[stable(feature = "move_cell", since = "1.17.0")]
407407
pub fn replace(&self, val: T) -> T {

0 commit comments

Comments
 (0)