]> git.proxmox.com Git - rustc.git/blob - src/doc/book/listings/ch18-patterns-and-matching/listing-18-15/src/main.rs
New upstream version 1.43.0+dfsg1
[rustc.git] / src / doc / book / listings / ch18-patterns-and-matching / listing-18-15 / src / main.rs
1 enum Message {
2 Quit,
3 Move { x: i32, y: i32 },
4 Write(String),
5 ChangeColor(i32, i32, i32),
6 }
7
8 fn main() {
9 let msg = Message::ChangeColor(0, 160, 255);
10
11 match msg {
12 Message::Quit => {
13 println!("The Quit variant has no data to destructure.")
14 }
15 Message::Move { x, y } => {
16 println!(
17 "Move in the x direction {} and in the y direction {}",
18 x, y
19 );
20 }
21 Message::Write(text) => println!("Text message: {}", text),
22 Message::ChangeColor(r, g, b) => println!(
23 "Change the color to red {}, green {}, and blue {}",
24 r, g, b
25 ),
26 }
27 }