See also X-Link mem::{swap, take, replace}
This commit is contained in:
parent
8141873e6d
commit
e720f4237a
1 changed files with 16 additions and 0 deletions
|
@ -670,6 +670,9 @@ pub unsafe fn uninitialized<T>() -> T {
|
||||||
|
|
||||||
/// Swaps the values at two mutable locations, without deinitializing either one.
|
/// Swaps the values at two mutable locations, without deinitializing either one.
|
||||||
///
|
///
|
||||||
|
/// * If you want to swap with a default or dummy value, see [`take`].
|
||||||
|
/// * If you want to swap with a passed value, returning the old value, see [`replace`].
|
||||||
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -683,6 +686,9 @@ pub unsafe fn uninitialized<T>() -> T {
|
||||||
/// assert_eq!(42, x);
|
/// assert_eq!(42, x);
|
||||||
/// assert_eq!(5, y);
|
/// assert_eq!(5, y);
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// [`replace`]: fn.replace.html
|
||||||
|
/// [`take`]: fn.take.html
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn swap<T>(x: &mut T, y: &mut T) {
|
pub fn swap<T>(x: &mut T, y: &mut T) {
|
||||||
|
@ -695,6 +701,9 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
|
||||||
|
|
||||||
/// Replaces `dest` with the default value of `T`, returning the previous `dest` value.
|
/// Replaces `dest` with the default value of `T`, returning the previous `dest` value.
|
||||||
///
|
///
|
||||||
|
/// * If you want to replace the values of two variables, see [`swap`].
|
||||||
|
/// * If you want to replace with a passed value instead of the default value, see [`replace`].
|
||||||
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// A simple example:
|
/// A simple example:
|
||||||
|
@ -747,6 +756,8 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`Clone`]: ../../std/clone/trait.Clone.html
|
/// [`Clone`]: ../../std/clone/trait.Clone.html
|
||||||
|
/// [`replace`]: fn.replace.html
|
||||||
|
/// [`swap`]: fn.swap.html
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "mem_take", since = "1.40.0")]
|
#[stable(feature = "mem_take", since = "1.40.0")]
|
||||||
pub fn take<T: Default>(dest: &mut T) -> T {
|
pub fn take<T: Default>(dest: &mut T) -> T {
|
||||||
|
@ -757,6 +768,9 @@ pub fn take<T: Default>(dest: &mut T) -> T {
|
||||||
///
|
///
|
||||||
/// Neither value is dropped.
|
/// Neither value is dropped.
|
||||||
///
|
///
|
||||||
|
/// * If you want to replace the values of two variables, see [`swap`].
|
||||||
|
/// * If you want to replace with a default value, see [`take`].
|
||||||
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// A simple example:
|
/// A simple example:
|
||||||
|
@ -810,6 +824,8 @@ pub fn take<T: Default>(dest: &mut T) -> T {
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`Clone`]: ../../std/clone/trait.Clone.html
|
/// [`Clone`]: ../../std/clone/trait.Clone.html
|
||||||
|
/// [`swap`]: fn.swap.html
|
||||||
|
/// [`take`]: fn.take.html
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[must_use = "if you don't need the old value, you can just assign the new value directly"]
|
#[must_use = "if you don't need the old value, you can just assign the new value directly"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue