1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2024-12-11 13:18:43 +02:00

Lecture notes for Destructing Arrays (#266)

* Lecture notes for Destructing Arrays

* Update destructuring-arrays.md
This commit is contained in:
Charisee Chiw 2023-02-22 04:41:12 -08:00 committed by GitHub
parent c88738db02
commit 8ee637d886
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,10 +6,12 @@ You can destructure arrays, tuples, and slices by matching on their elements:
{{#include ../../third_party/rust-by-example/destructuring-arrays.rs}}
```
<details>
* Destructuring of slices of unknown length also works with patterns of fixed length.
```rust,editable
fn main() {
inspect(&[0, -2, 3]);
@ -26,5 +28,10 @@ fn inspect(slice: &[i32]) {
}
}
```
* Create a new pattern using `_` to represent an element.
* Add more values to the array.
* Point out that how `..` will expand to account for different number of elements.
* Show matching against the tail with patterns `[.., b]` and `[a@..,b]`
</details>