mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-21 17:52:12 +03:00
Rollup merge of #86549 - mbartlett21:patch-1, r=GuillaumeGomez
Add destructuring example of E0508 This adds an example that destructures the array to move the value, instead of taking a reference or cloning.
This commit is contained in:
@@ -39,3 +39,16 @@ fn main() {
|
||||
let _value = array[0].clone();
|
||||
}
|
||||
```
|
||||
|
||||
If you really want to move the value out, you can use a destructuring array
|
||||
pattern to move it:
|
||||
|
||||
```
|
||||
struct NonCopy;
|
||||
|
||||
fn main() {
|
||||
let array = [NonCopy; 1];
|
||||
// Destructuring the array
|
||||
let [_value] = array;
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user