1
Fork 0

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:
mbartlett21 2021-06-22 22:24:46 +10:00 committed by GitHub
parent 75ed34223a
commit 9db5c483ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;
}
```