mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-05-15 01:52:42 +00:00
26 lines
858 B
Rust
26 lines
858 B
Rust
// ./src/flow_control/match/destructuring/destructure_tuple.md
|
|
|
|
|
|
fn part0() {
|
|
let triple = (0, -2, 3);
|
|
// TODO ^ Try different values for `triple`
|
|
|
|
println!("Tell me about {:?}", triple);
|
|
// Match can be used to destructure a tuple
|
|
match triple {
|
|
// Destructure the second and third elements
|
|
(0, y, z) => println!("First is `0`, `y` is {:?}, and `z` is {:?}", y, z),
|
|
(1, ..) => println!("First is `1` and the rest doesn't matter"),
|
|
(.., 2) => println!("last is `2` and the rest doesn't matter"),
|
|
(3, .., 4) => println!("First is `3`, last is `4`, and the rest doesn't matter"),
|
|
// `..` can be used to ignore the rest of the tuple
|
|
_ => println!("It doesn't matter what they are"),
|
|
// `_` means don't bind the value to a variable
|
|
}
|
|
}
|
|
|
|
pub fn main() {
|
|
part0();
|
|
}
|
|
|