File tree 1 file changed +13
-1
lines changed
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> {
367
367
/// ```
368
368
/// let x = Box::new(5);
369
369
/// 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);
370
376
/// ```
371
377
#[ rustfmt:: skip]
372
378
#[ inline]
373
379
fn clone ( & self ) -> Box < T > {
374
380
box { ( * * self ) . clone ( ) }
375
381
}
382
+
376
383
/// Copies `source`'s contents into `self` without creating a new allocation.
377
384
///
378
385
/// # Examples
379
386
///
380
387
/// ```
381
388
/// let x = Box::new(5);
382
389
/// let mut y = Box::new(10);
390
+ /// let yp: *const i32 = &*y;
383
391
///
384
392
/// y.clone_from(&x);
385
393
///
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);
387
399
/// ```
388
400
#[ inline]
389
401
fn clone_from ( & mut self , source : & Box < T > ) {
You can’t perform that action at this time.
0 commit comments