about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-06-11 17:14:01 +0200
committerGitHub <noreply@github.com>2019-06-11 17:14:01 +0200
commit79ac25470320717db398516ecdeda0a423371a00 (patch)
treeb965620379032565e32034ea68a2e670644271f0 /src/libstd
parentb4419a8b05f4b5793f2dca801c83db576d8b39f4 (diff)
parent3cfceb94cfa42e936a9e115c571c0b0de0f1a262 (diff)
downloadrust-79ac25470320717db398516ecdeda0a423371a00.tar.gz
rust-79ac25470320717db398516ecdeda0a423371a00.zip
Rollup merge of #61652 - JohnTitor:docs-improve-array, r=Centril
Mention slice patterns in array

Fixes #61650

r? @scottmcm
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/primitive_docs.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/libstd/primitive_docs.rs b/src/libstd/primitive_docs.rs
index 42b64d2b5a5..e78a5defdf3 100644
--- a/src/libstd/primitive_docs.rs
+++ b/src/libstd/primitive_docs.rs
@@ -482,8 +482,8 @@ mod prim_pointer { }
 /// an array. Indeed, this provides most of the API for working with arrays.
 /// Slices have a dynamic size and do not coerce to arrays.
 ///
-/// There is no way to move elements out of an array. See [`mem::replace`][replace]
-/// for an alternative.
+/// You can move elements out of an array with a slice pattern. If you want
+/// one element, see [`mem::replace`][replace].
 ///
 /// # Examples
 ///
@@ -525,6 +525,16 @@ mod prim_pointer { }
 /// for x in &array { }
 /// ```
 ///
+/// You can use a slice pattern to move elements out of an array:
+///
+/// ```
+/// fn move_away(_: String) { /* Do interesting things. */ }
+///
+/// let [john, roa] = ["John".to_string(), "Roa".to_string()];
+/// move_away(john);
+/// move_away(roa);
+/// ```
+///
 /// [slice]: primitive.slice.html
 /// [copy]: marker/trait.Copy.html
 /// [clone]: clone/trait.Clone.html