@@ -403,10 +403,8 @@ pub fn from_be32(x: u32) -> u32 { ByteOrder::from_big_endian(x) }
403
403
#[ stable]
404
404
pub fn from_be64 ( x : u64 ) -> u64 { ByteOrder :: from_big_endian ( x) }
405
405
406
- /**
407
- * Swap the values at two mutable locations of the same type, without
408
- * deinitialising or copying either one.
409
- */
406
+ /// Swap the values at two mutable locations of the same type, without
407
+ /// deinitialising or copying either one.
410
408
#[ inline]
411
409
#[ stable]
412
410
pub fn swap < T > ( x : & mut T , y : & mut T ) {
@@ -425,42 +423,40 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
425
423
}
426
424
}
427
425
428
- /**
429
- * Replace the value at a mutable location with a new one, returning the old
430
- * value, without deinitialising or copying either one.
431
- *
432
- * This is primarily used for transferring and swapping ownership of a value
433
- * in a mutable location. For example, this function allows consumption of
434
- * one field of a struct by replacing it with another value. The normal approach
435
- * doesn't always work:
436
- *
437
- * ```rust,ignore
438
- * struct Buffer<T> { buf: Vec<T> }
439
- *
440
- * impl<T> Buffer<T> {
441
- * fn get_and_reset(&mut self) -> Vec<T> {
442
- * // error: cannot move out of dereference of `&mut`-pointer
443
- * let buf = self.buf;
444
- * self.buf = Vec::new();
445
- * buf
446
- * }
447
- * }
448
- * ```
449
- *
450
- * Note that `T` does not necessarily implement `Clone`, so it can't even
451
- * clone and reset `self.buf`. But `replace` can be used to disassociate
452
- * the original value of `self.buf` from `self`, allowing it to be returned:
453
- *
454
- * ```rust
455
- * # struct Buffer<T> { buf: Vec<T> }
456
- * impl<T> Buffer<T> {
457
- * fn get_and_reset(&mut self) -> Vec<T> {
458
- * use std::mem::replace;
459
- * replace(&mut self.buf, Vec::new())
460
- * }
461
- * }
462
- * ```
463
- */
426
+ /// Replace the value at a mutable location with a new one, returning the old
427
+ /// value, without deinitialising or copying either one.
428
+ ///
429
+ /// This is primarily used for transferring and swapping ownership of a value
430
+ /// in a mutable location. For example, this function allows consumption of
431
+ /// one field of a struct by replacing it with another value. The normal approach
432
+ /// doesn't always work:
433
+ ///
434
+ /// ```rust,ignore
435
+ /// struct Buffer<T> { buf: Vec<T> }
436
+ ///
437
+ /// impl<T> Buffer<T> {
438
+ /// fn get_and_reset(&mut self) -> Vec<T> {
439
+ /// // error: cannot move out of dereference of `&mut`-pointer
440
+ /// let buf = self.buf;
441
+ /// self.buf = Vec::new();
442
+ /// buf
443
+ /// }
444
+ /// }
445
+ /// ```
446
+ ///
447
+ /// Note that `T` does not necessarily implement `Clone`, so it can't even
448
+ /// clone and reset `self.buf`. But `replace` can be used to disassociate
449
+ /// the original value of `self.buf` from `self`, allowing it to be returned:
450
+ ///
451
+ /// ```rust
452
+ /// # struct Buffer<T> { buf: Vec<T> }
453
+ /// impl<T> Buffer<T> {
454
+ /// fn get_and_reset(&mut self) -> Vec<T> {
455
+ /// use std::mem::replace;
456
+ /// replace(&mut self.buf, Vec::new())
457
+ /// }
458
+ /// }
459
+ /// ```
464
460
#[ inline]
465
461
#[ stable]
466
462
pub fn replace < T > ( dest : & mut T , mut src : T ) -> T {
0 commit comments