From 1a32a68f38a9d74209fb710187a1909af8b1979d Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 8 Jun 2019 16:13:15 +0900 Subject: [PATCH 1/2] Mention slice patterns --- src/libstd/primitive_docs.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/primitive_docs.rs b/src/libstd/primitive_docs.rs index 24f728158c472..0ba6e99e61342 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 /// From 3cfceb94cfa42e936a9e115c571c0b0de0f1a262 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Mon, 10 Jun 2019 13:30:45 +0900 Subject: [PATCH 2/2] Add an example --- src/libstd/primitive_docs.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libstd/primitive_docs.rs b/src/libstd/primitive_docs.rs index 0ba6e99e61342..7ed40bfe6d8de 100644 --- a/src/libstd/primitive_docs.rs +++ b/src/libstd/primitive_docs.rs @@ -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