From 2186d3558cb5dbe9b8712b9ad2204527b9ee70fc Mon Sep 17 00:00:00 2001 From: Hunter Kvalevog Date: Sat, 19 Sep 2026 17:51:45 -0500 Subject: rustlings: complete 08 --- rustlings/solutions/08_enums/enums2.rs | 37 ++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'rustlings/solutions/08_enums/enums2.rs') 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(); + } } -- cgit v1.2.3