From 892f693cfdcec69420ff639a4ee178e419ccc4d3 Mon Sep 17 00:00:00 2001 From: Justin Kelz Date: Thu, 24 Mar 2022 22:06:04 -0700 Subject: [PATCH] Finished enums --- exercises/enums/enums3.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/exercises/enums/enums3.rs b/exercises/enums/enums3.rs index 178b40c4..535fb575 100644 --- a/exercises/enums/enums3.rs +++ b/exercises/enums/enums3.rs @@ -1,10 +1,15 @@ // enums3.rs // Address all the TODOs to make the tests pass! -// I AM NOT DONE +// Hey, Future Justin! Come back and really dig through this. You had to use https://gist.github.com/Coutlaw/89dd16a5f7eb852c4ee44a3094bcdc09#file-enums_solution-rs, +// But you barely hacked through this enum Message { // TODO: implement the message variant types based on their usage below + ChangeColor((u8,u8,u8)), + Echo(String), + Move{x:u8,y:u8}, + Quit, } struct Point { @@ -37,6 +42,12 @@ impl State { fn process(&mut self, message: Message) { // TODO: create a match expression to process the different message variants + match message{ + Message::ChangeColor((r, g, b)) => self.change_color((r, g, b)), + Message::Echo(s) => self.echo(s), + Message::Move{x, y} => self.move_position(Point{x, y}), + Message::Quit => self.quit() + } } } @@ -53,7 +64,7 @@ mod tests { }; state.process(Message::ChangeColor((255, 0, 255))); state.process(Message::Echo(String::from("hello world"))); - state.process(Message::Move(Point { x: 10, y: 15 })); + state.process(Message::Move{ x: 10, y: 15 }); state.process(Message::Quit); assert_eq!(state.color, (255, 0, 255));