mirror of https://github.com/rust-lang/rustlings
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
550 B
Rust
31 lines
550 B
Rust
5 years ago
|
// enums2.rs
|
||
1 year ago
|
//
|
||
|
// Execute `rustlings hint enums2` or use the `hint` watch subcommand for a
|
||
|
// hint.
|
||
5 years ago
|
|
||
5 years ago
|
// I AM NOT DONE
|
||
|
|
||
5 years ago
|
#[derive(Debug)]
|
||
|
enum Message {
|
||
|
// TODO: define the different variants used below
|
||
|
}
|
||
|
|
||
|
impl Message {
|
||
|
fn call(&self) {
|
||
2 years ago
|
println!("{:?}", self);
|
||
5 years ago
|
}
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
let messages = [
|
||
4 years ago
|
Message::Move { x: 10, y: 30 },
|
||
5 years ago
|
Message::Echo(String::from("hello world")),
|
||
|
Message::ChangeColor(200, 255, 255),
|
||
4 years ago
|
Message::Quit,
|
||
5 years ago
|
];
|
||
|
|
||
|
for message in &messages {
|
||
|
message.call();
|
||
|
}
|
||
|
}
|