mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-12 13:49:19 +00:00
Solve enum3
This commit is contained in:
parent
53c7b873de
commit
3bdf1774da
@ -1,10 +1,12 @@
|
|||||||
// enums3.rs
|
// enums3.rs
|
||||||
// Address all the TODOs to make the tests pass!
|
// Address all the TODOs to make the tests pass!
|
||||||
|
|
||||||
// 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
|
||||||
|
ChangeColor((u8, u8, u8)),
|
||||||
|
Echo(String),
|
||||||
|
Move(Point),
|
||||||
|
Quit,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Point {
|
struct Point {
|
||||||
@ -37,6 +39,20 @@ impl State {
|
|||||||
|
|
||||||
fn process(&mut self, message: Message) {
|
fn process(&mut self, message: Message) {
|
||||||
// TODO: create a match expression to process the different message variants
|
// 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::Move(p) => {
|
||||||
|
self.move_position(p);
|
||||||
|
}
|
||||||
|
Message::Quit => {
|
||||||
|
self.quit();
|
||||||
|
}
|
||||||
|
Message::Echo(s) => {
|
||||||
|
self.echo(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user