mirror of https://github.com/rust-lang/book
28 lines
677 B
Rust
28 lines
677 B
Rust
enum Message {
|
|
Quit,
|
|
Move { x: i32, y: i32 },
|
|
Write(String),
|
|
ChangeColor(i32, i32, i32),
|
|
}
|
|
|
|
fn main() {
|
|
let msg = Message::ChangeColor(0, 160, 255);
|
|
|
|
match msg {
|
|
Message::Quit => {
|
|
println!("The Quit variant has no data to destructure.");
|
|
}
|
|
Message::Move { x, y } => {
|
|
println!(
|
|
"Move in the x direction {x} and in the y direction {y}"
|
|
);
|
|
}
|
|
Message::Write(text) => {
|
|
println!("Text message: {text}");
|
|
}
|
|
Message::ChangeColor(r, g, b) => println!(
|
|
"Change the color to red {r}, green {g}, and blue {b}",
|
|
),
|
|
}
|
|
}
|