summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Scheel <Ryan.havvy@gmail.com>2020-08-01 22:56:25 -0700
committerGitHub <noreply@github.com>2020-08-01 22:56:25 -0700
commite720f4237a39dba0a4b741812de59d1654b3b253 (patch)
tree057c2f2155388ab58a13a0fbfe0e862e88ec4f5f
parent8141873e6d50a0a0829fd756b0a16a92b27cfe22 (diff)
downloadrust-Havvy-patch-1.tar.gz
See also X-Link mem::{swap, take, replace}Havvy-patch-1
-rw-r--r--library/core/src/mem/mod.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs
index 4e58e118562..9107c570a89 100644
--- a/library/core/src/mem/mod.rs
+++ b/library/core/src/mem/mod.rs
@@ -670,6 +670,9 @@ pub unsafe fn uninitialized<T>() -> T {
/// 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
///
/// ```
@@ -683,6 +686,9 @@ pub unsafe fn uninitialized<T>() -> T {
/// assert_eq!(42, x);
/// assert_eq!(5, y);
/// ```
+///
+/// [`replace`]: fn.replace.html
+/// [`take`]: fn.take.html
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
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.
///
+/// * 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
///
/// A simple example:
@@ -747,6 +756,8 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
/// ```
///
/// [`Clone`]: ../../std/clone/trait.Clone.html
+/// [`replace`]: fn.replace.html
+/// [`swap`]: fn.swap.html
#[inline]
#[stable(feature = "mem_take", since = "1.40.0")]
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.
///
+/// * If you want to replace the values of two variables, see [`swap`].
+/// * If you want to replace with a default value, see [`take`].
+///
/// # Examples
///
/// A simple example:
@@ -810,6 +824,8 @@ pub fn take<T: Default>(dest: &mut T) -> T {
/// ```
///
/// [`Clone`]: ../../std/clone/trait.Clone.html
+/// [`swap`]: fn.swap.html
+/// [`take`]: fn.take.html
#[inline]
#[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"]