summaryrefslogtreecommitdiff
path: root/rustlings/solutions/08_enums/enums2.rs
diff options
context:
space:
mode:
authorHunter Kvalevog <hunter@kvog.sh>2026-09-19 17:51:45 -0500
committerHunter Kvalevog <hunter@kvog.sh>2026-09-19 17:51:45 -0500
commit2186d3558cb5dbe9b8712b9ad2204527b9ee70fc (patch)
treea88b701ddca88d16b10f1128f13fbc021ed299fd /rustlings/solutions/08_enums/enums2.rs
parent13c7b05a26b78cb63bed5d2afdf8eb927197286e (diff)
rustlings: complete 08
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();
+ }
}