This commit is contained in:
Daniil Moiseev 2022-09-22 21:34:25 +00:00 committed by Daniil
parent a2c4ec5cce
commit 239e33f221
3 changed files with 18 additions and 6 deletions

View File

@ -2,11 +2,13 @@
// //
// No hints this time! ;) // No hints this time! ;)
// I AM NOT DONE
#[derive(Debug)] #[derive(Debug)]
enum Message { enum Message {
// TODO: define a few types of messages as used below // TODO: define a few types of messages as used below
Quit,
Echo,
Move,
ChangeColor,
} }
fn main() { fn main() {

View File

@ -3,11 +3,13 @@
// Execute `rustlings hint enums2` or use the `hint` watch subcommand for a // Execute `rustlings hint enums2` or use the `hint` watch subcommand for a
// hint. // hint.
// I AM NOT DONE
#[derive(Debug)] #[derive(Debug)]
enum Message { enum Message {
// TODO: define the different variants used below // TODO: define the different variants used below
Move {x: i32, y: i32},
Echo(String),
ChangeColor(i32, i32, i32),
Quit,
} }
impl Message { impl Message {

View File

@ -5,10 +5,12 @@
// Execute `rustlings hint enums3` or use the `hint` watch subcommand for a // Execute `rustlings hint enums3` or use the `hint` watch subcommand for a
// hint. // hint.
// I AM NOT DONE
enum Message { enum Message {
// TODO: implement the message variant types based on their usage below // TODO: implement the message variant types based on their usage below
Move(Point),
Echo(String),
ChangeColor((u8, u8, u8)),
Quit,
} }
struct Point { struct Point {
@ -43,6 +45,12 @@ impl State {
// variants // variants
// Remember: When passing a tuple as a function argument, you'll need // Remember: When passing a tuple as a function argument, you'll need
// extra parentheses: fn function((t, u, p, l, e)) // extra parentheses: fn function((t, u, p, l, e))
match message {
Message::ChangeColor(t) => self.change_color(t),
Message::Echo(s) => self.echo(s),
Message::Move(Point{x,y}) => self.move_position(Point{x, y}),
Message::Quit => self.quit()
}
} }
} }