mirror of https://github.com/KaiserY/trpl-zh-cn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
647 B
26 lines
647 B
4 years ago
|
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 => {
|
||
3 years ago
|
println!("The Quit variant has no data to destructure.");
|
||
4 years ago
|
}
|
||
|
Message::Move { x, y } => {
|
||
3 years ago
|
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) => {
|
||
1 year ago
|
println!("Change the color to red {r}, green {g}, and blue {b}")
|
||
4 years ago
|
}
|
||
|
}
|
||
|
}
|