mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-04-20 23:16:56 +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}}
|
{{#include ../../third_party/rust-by-example/destructuring-arrays.rs}}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
|
|
||||||
* Destructuring of slices of unknown length also works with patterns of fixed length.
|
* Destructuring of slices of unknown length also works with patterns of fixed length.
|
||||||
|
|
||||||
|
|
||||||
```rust,editable
|
```rust,editable
|
||||||
fn main() {
|
fn main() {
|
||||||
inspect(&[0, -2, 3]);
|
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]`
|
* Show matching against the tail with patterns `[.., b]` and `[a@..,b]`
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user