diff --git a/exercises/enums/enums1.rs b/exercises/enums/enums1.rs index 25525b2..2bcb132 100644 --- a/exercises/enums/enums1.rs +++ b/exercises/enums/enums1.rs @@ -2,11 +2,13 @@ // // No hints this time! ;) -// I AM NOT DONE #[derive(Debug)] enum Message { - // TODO: define a few types of messages as used below + Quit, + Echo, + Move, + ChangeColor } fn main() { diff --git a/exercises/enums/enums2.rs b/exercises/enums/enums2.rs index df93fe0..f6f3dbe 100644 --- a/exercises/enums/enums2.rs +++ b/exercises/enums/enums2.rs @@ -3,11 +3,13 @@ // Execute `rustlings hint enums2` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE #[derive(Debug)] enum Message { - // TODO: define the different variants used below + Move { x: i32, y: i32}, + Echo(String), + ChangeColor(i32, i32, i32), + Quit } impl Message { diff --git a/exercises/enums/enums3.rs b/exercises/enums/enums3.rs index 2dcdad0..dd97f79 100644 --- a/exercises/enums/enums3.rs +++ b/exercises/enums/enums3.rs @@ -5,10 +5,12 @@ // Execute `rustlings hint enums3` or use the `hint` watch subcommand for a // hint. -// I AM NOT DONE enum Message { - // TODO: implement the message variant types based on their usage below + Move(Point), + Echo(String), + ChangeColor(u8, u8, u8), + Quit } struct Point { @@ -45,6 +47,12 @@ impl State { // variants // Remember: When passing a tuple as a function argument, you'll need // extra parentheses: fn function((t, u, p, l, e)) + match message { + Message::Move(point) => self.move_position(point), + Message::Echo(echo) => self.echo(echo), + Message::ChangeColor(red, green, blue) => self.change_color((red,green,blue)), + Message::Quit => self.quit(), + } } }