mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-02-25 13:52:18 +08:00
28 lines
603 B
Rust
28 lines
603 B
Rust
|
enum Color {
|
||
|
Rgb(i32, i32, i32),
|
||
|
Hsv(i32, i32, i32),
|
||
|
}
|
||
|
|
||
|
enum Message {
|
||
|
Quit,
|
||
|
Move { x: i32, y: i32 },
|
||
|
Write(String),
|
||
|
ChangeColor(Color),
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
let msg = Message::ChangeColor(Color::Hsv(0, 160, 255));
|
||
|
|
||
|
match msg {
|
||
|
Message::ChangeColor(Color::Rgb(r, g, b)) => println!(
|
||
|
"Change the color to red {}, green {}, and blue {}",
|
||
|
r, g, b
|
||
|
),
|
||
|
Message::ChangeColor(Color::Hsv(h, s, v)) => println!(
|
||
|
"Change the color to hue {}, saturation {}, and value {}",
|
||
|
h, s, v
|
||
|
),
|
||
|
_ => (),
|
||
|
}
|
||
|
}
|