diff options
| author | Matthias Richter <matthias.ri97@gmail.com> | 2023-11-14 08:19:15 +0100 |
|---|---|---|
| committer | Matthias Richter <matthias.ri97@gmail.com> | 2023-11-14 08:19:40 +0100 |
| commit | 77b687d501771c24bd83294d97b8e6f9ffa92d6b (patch) | |
| tree | 05edcd14affc7c10650d4b1f711aa45a6067aea5 /exercises/08_enums/enums3.rs | |
| parent | bc3808cf29323a244762b47bf7d3f391d353fdf1 (diff) | |
fix(enums) make enum variants more consistent
closes #1545
Diffstat (limited to 'exercises/08_enums/enums3.rs')
| -rw-r--r-- | exercises/08_enums/enums3.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/exercises/08_enums/enums3.rs b/exercises/08_enums/enums3.rs index 92d18c4..fffb9d0 100644 --- a/exercises/08_enums/enums3.rs +++ b/exercises/08_enums/enums3.rs @@ -18,6 +18,8 @@ struct Point { struct State { color: (u8, u8, u8), + width: u8, + height: u8, position: Point, quit: bool, message: String, @@ -36,6 +38,11 @@ impl State { self.message = s } + fn resize(&mut self, w: u8, h: u8) { + self.width = w; + self.height = h; + } + fn move_position(&mut self, p: Point) { self.position = p; } @@ -55,16 +62,21 @@ mod tests { fn test_match_message_call() { let mut state = State { quit: false, + width: 0, + height: 0, position: Point { x: 0, y: 0 }, color: (0, 0, 0), message: "hello world".to_string(), }; state.process(Message::ChangeColor(255, 0, 255)); state.process(Message::Echo(String::from("Hello world!"))); + state.process(Message::Resize { w: 10, h: 30 }); state.process(Message::Move(Point { x: 10, y: 15 })); state.process(Message::Quit); assert_eq!(state.color, (255, 0, 255)); + assert_eq!(state.width, 10); + assert_eq!(state.height, 30); assert_eq!(state.position.x, 10); assert_eq!(state.position.y, 15); assert_eq!(state.quit, true); |
