add solutions to this exercise but incomplete
This commit is contained in:
parent
14c156b7ac
commit
5480d357c3
|
@ -5,6 +5,10 @@
|
||||||
|
|
||||||
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 {x: i32, y: i32},
|
||||||
|
Echo (String),
|
||||||
|
ChangeColor (i32, i32, i32),
|
||||||
|
Quit,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Point {
|
struct Point {
|
||||||
|
@ -37,6 +41,13 @@ 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::Move => {x: i32, y: i32},
|
||||||
|
Message::Echo => { String },
|
||||||
|
Message::ChangeColor => { i32, i32, i32 },
|
||||||
|
Message::Quit => {},
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,9 +62,10 @@ mod tests {
|
||||||
position: Point { x: 0, y: 0 },
|
position: Point { x: 0, y: 0 },
|
||||||
color: (0, 0, 0),
|
color: (0, 0, 0),
|
||||||
};
|
};
|
||||||
state.process(Message::ChangeColor((255, 0, 255)));
|
state.process(Message::ChangeColor(255, 0, 255));
|
||||||
state.process(Message::Echo(String::from("hello world")));
|
state.process(Message::Echo(String::from("hello world")));
|
||||||
state.process(Message::Move(Point { x: 10, y: 15 }));
|
//state.process(Message::Move(Point { x: 10, y: 15 }));
|
||||||
|
state.process(Message::Move { x: 10, y: 15 });
|
||||||
state.process(Message::Quit);
|
state.process(Message::Quit);
|
||||||
|
|
||||||
assert_eq!(state.color, (255, 0, 255));
|
assert_eq!(state.color, (255, 0, 255));
|
||||||
|
|
Loading…
Reference in a new issue