enums done

This commit is contained in:
David E. Perez Negron R. 2023-11-03 01:10:06 -06:00
parent 6fad289cb4
commit da76123b1f
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 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 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 Move(Point),
Echo(String),
ChangeColor(u8, u8, u8),
Quit
} }
struct Point { struct Point {
@ -45,6 +47,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::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(),
}
} }
} }