enums done
This commit is contained in:
parent
6fad289cb4
commit
da76123b1f
|
@ -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() {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue