mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-03 01:09:18 +00:00
31 lines
560 B
Rust
31 lines
560 B
Rust
// enums2.rs
|
|
// Make me compile! Execute `rustlings hint enums2` for hints!
|
|
|
|
|
|
#[derive(Debug)]
|
|
enum Message {
|
|
Quit,
|
|
Echo(String),// a tuple with one elem
|
|
Move{x: i32, y: i32},
|
|
ChangeColor(u8, u8, u8),
|
|
}
|
|
|
|
impl Message {
|
|
fn call(&self) {
|
|
println!("{:?}", &self);
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let messages = [
|
|
Message::Move{ x: 10, y: 30 },
|
|
Message::Echo(String::from("hello world")),
|
|
Message::ChangeColor(200, 255, 255),
|
|
Message::Quit
|
|
];
|
|
|
|
for message in &messages {
|
|
message.call();
|
|
}
|
|
}
|