Skip to content

Commit 79ac254

Browse files
authored
Rollup merge of rust-lang#61652 - JohnTitor:docs-improve-array, r=Centril
Mention slice patterns in array Fixes rust-lang#61650 r? @scottmcm
2 parents b4419a8 + 3cfceb9 commit 79ac254

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/libstd/primitive_docs.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@ mod prim_pointer { }
482482
/// an array. Indeed, this provides most of the API for working with arrays.
483483
/// Slices have a dynamic size and do not coerce to arrays.
484484
///
485-
/// There is no way to move elements out of an array. See [`mem::replace`][replace]
486-
/// for an alternative.
485+
/// You can move elements out of an array with a slice pattern. If you want
486+
/// one element, see [`mem::replace`][replace].
487487
///
488488
/// # Examples
489489
///
@@ -525,6 +525,16 @@ mod prim_pointer { }
525525
/// for x in &array { }
526526
/// ```
527527
///
528+
/// You can use a slice pattern to move elements out of an array:
529+
///
530+
/// ```
531+
/// fn move_away(_: String) { /* Do interesting things. */ }
532+
///
533+
/// let [john, roa] = ["John".to_string(), "Roa".to_string()];
534+
/// move_away(john);
535+
/// move_away(roa);
536+
/// ```
537+
///
528538
/// [slice]: primitive.slice.html
529539
/// [copy]: marker/trait.Copy.html
530540
/// [clone]: clone/trait.Clone.html

0 commit comments

Comments
 (0)