File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -367,23 +367,35 @@ impl<T: Clone> Clone for Box<T> {
367367 /// ```
368368 /// let x = Box::new(5);
369369 /// let y = x.clone();
370+ ///
371+ /// // The value is the same
372+ /// assert_eq!(x, y);
373+ ///
374+ /// // But they are unique objects
375+ /// assert_ne!(&*x as *const i32, &*y as *const i32);
370376 /// ```
371377 #[ rustfmt:: skip]
372378 #[ inline]
373379 fn clone ( & self ) -> Box < T > {
374380 box { ( * * self ) . clone ( ) }
375381 }
382+
376383 /// Copies `source`'s contents into `self` without creating a new allocation.
377384 ///
378385 /// # Examples
379386 ///
380387 /// ```
381388 /// let x = Box::new(5);
382389 /// let mut y = Box::new(10);
390+ /// let yp: *const i32 = &*y;
383391 ///
384392 /// y.clone_from(&x);
385393 ///
386- /// assert_eq!(*y, 5);
394+ /// // The value is the same
395+ /// assert_eq!(x, y);
396+ ///
397+ /// // And no allocation occurred
398+ /// assert_eq!(yp, &*y);
387399 /// ```
388400 #[ inline]
389401 fn clone_from ( & mut self , source : & Box < T > ) {
You can’t perform that action at this time.
0 commit comments