Skip to content

Commit 9e50540

Browse files
brendanzabalexcrichton
authored andcommitted
---
yaml --- r: 152655 b: refs/heads/try2 c: 4c0f8f4 h: refs/heads/master i: 152653: eb36a99 152651: 37eaee3 152647: 9802e87 152639: 714cf90 v: v3
1 parent 274527d commit 9e50540

File tree

2 files changed

+37
-41
lines changed

2 files changed

+37
-41
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: b84d17d4d77b04e1b7784d95e0c3cb2dca16f344
8+
refs/heads/try2: 4c0f8f49f6fe860efa268efa2f4fa0b5f00a4b07
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/mem.rs

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,8 @@ pub fn from_be32(x: u32) -> u32 { ByteOrder::from_big_endian(x) }
403403
#[stable]
404404
pub fn from_be64(x: u64) -> u64 { ByteOrder::from_big_endian(x) }
405405

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.
410408
#[inline]
411409
#[stable]
412410
pub fn swap<T>(x: &mut T, y: &mut T) {
@@ -425,42 +423,40 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
425423
}
426424
}
427425

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+
/// ```
464460
#[inline]
465461
#[stable]
466462
pub fn replace<T>(dest: &mut T, mut src: T) -> T {

0 commit comments

Comments
 (0)