mirror of
https://github.com/notohh/rustlings.git
synced 2024-12-18 06:58:10 -05:00
37 lines
638 B
Rust
37 lines
638 B
Rust
#[derive(Debug)]
|
|
struct Point {
|
|
x: u64,
|
|
y: u64,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
enum Message {
|
|
Resize { width: u64, height: u64 },
|
|
Move(Point),
|
|
Echo(String),
|
|
ChangeColor(u8, u8, u8),
|
|
Quit,
|
|
}
|
|
|
|
impl Message {
|
|
fn call(&self) {
|
|
println!("{self:?}");
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let messages = [
|
|
Message::Resize {
|
|
width: 10,
|
|
height: 30,
|
|
},
|
|
Message::Move(Point { x: 10, y: 15 }),
|
|
Message::Echo(String::from("hello world")),
|
|
Message::ChangeColor(200, 255, 255),
|
|
Message::Quit,
|
|
];
|
|
|
|
for message in &messages {
|
|
message.call();
|
|
}
|
|
}
|