1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-15 22:00:26 +02:00

Indent code in speaker notes (#476)

* Indent code in speaker notes

#475

* Update stack.md

* Update destructuring-arrays.md

* Update hashmap.md

* Update traits.md
This commit is contained in:
Charisee Chiw
2023-03-11 14:12:32 -08:00
committed by GitHub
parent 368f3ba302
commit 59d3d7f625
5 changed files with 121 additions and 122 deletions

View File

@ -12,22 +12,22 @@ You can destructure arrays, tuples, and slices by matching on their elements:
* Destructuring of slices of unknown length also works with patterns of fixed length.
```rust,editable
fn main() {
inspect(&[0, -2, 3]);
inspect(&[0, -2, 3, 4]);
}
```rust,editable
fn main() {
inspect(&[0, -2, 3]);
inspect(&[0, -2, 3, 4]);
}
#[rustfmt::skip]
fn inspect(slice: &[i32]) {
println!("Tell me about {slice:?}");
match slice {
&[0, y, z] => println!("First is 0, y = {y}, and z = {z}"),
&[1, ..] => println!("First is 1 and the rest were ignored"),
_ => println!("All elements were ignored"),
}
}
```
#[rustfmt::skip]
fn inspect(slice: &[i32]) {
println!("Tell me about {slice:?}");
match slice {
&[0, y, z] => println!("First is 0, y = {y}, and z = {z}"),
&[1, ..] => println!("First is 1 and the rest were ignored"),
_ => println!("All elements were ignored"),
}
}
```
* Create a new pattern using `_` to represent an element.
* Add more values to the array.