Skip to content

Commit

Permalink
Improve box clone doctests to ensure the documentation is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
czipperz committed Jun 30, 2019
1 parent 0af8e87 commit fc70c37
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,23 +367,35 @@ impl<T: Clone> Clone for Box<T> {
/// ```
/// let x = Box::new(5);
/// let y = x.clone();
///
/// // The value is the same
/// assert_eq!(x, y);
///
/// // But they are unique objects
/// assert_ne!(&*x as *const i32, &*y as *const i32);
/// ```
#[rustfmt::skip]
#[inline]
fn clone(&self) -> Box<T> {
box { (**self).clone() }
}

/// Copies `source`'s contents into `self` without creating a new allocation.
///
/// # Examples
///
/// ```
/// let x = Box::new(5);
/// let mut y = Box::new(10);
/// let yp: *const i32 = &*y;
///
/// y.clone_from(&x);
///
/// assert_eq!(*y, 5);
/// // The value is the same
/// assert_eq!(x, y);
///
/// // And no allocation occurred
/// assert_eq!(yp, &*y);
/// ```
#[inline]
fn clone_from(&mut self, source: &Box<T>) {
Expand Down

0 comments on commit fc70c37

Please sign in to comment.