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:
parent
c88738db02
commit
8ee637d886
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user