summaryrefslogtreecommitdiff
path: root/rustlings/solutions/08_enums/enums2.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rustlings/solutions/08_enums/enums2.rs')
-rw-r--r--rustlings/solutions/08_enums/enums2.rs37
1 files changed, 35 insertions, 2 deletions
diff --git a/rustlings/solutions/08_enums/enums2.rs b/rustlings/solutions/08_enums/enums2.rs
index dcf2377..07aee26 100644
--- a/rustlings/solutions/08_enums/enums2.rs
+++ b/rustlings/solutions/08_enums/enums2.rs
@@ -1,4 +1,37 @@
+#[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() {
- // DON'T EDIT THIS SOLUTION FILE!
- // It will be automatically filled after you finish the exercise.
+ 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();
+ }
}