mirror of
https://github.com/notohh/rustlings.git
synced 2025-09-04 23:11:47 -04:00
Merge branch 'main' into comment_cleanup
This commit is contained in:
commit
b44472b237
8 changed files with 161 additions and 90 deletions
exercises/enums
|
@ -20,6 +20,7 @@ struct State {
|
|||
color: (u8, u8, u8),
|
||||
position: Point,
|
||||
quit: bool,
|
||||
message: String
|
||||
}
|
||||
|
||||
impl State {
|
||||
|
@ -31,9 +32,7 @@ impl State {
|
|||
self.quit = true;
|
||||
}
|
||||
|
||||
fn echo(&self, s: String) {
|
||||
println!("{}", s);
|
||||
}
|
||||
fn echo(&mut self, s: String) { self.message = s }
|
||||
|
||||
fn move_position(&mut self, p: Point) {
|
||||
self.position = p;
|
||||
|
@ -57,6 +56,7 @@ mod tests {
|
|||
quit: false,
|
||||
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")));
|
||||
|
@ -67,5 +67,6 @@ mod tests {
|
|||
assert_eq!(state.position.x, 10);
|
||||
assert_eq!(state.position.y, 15);
|
||||
assert_eq!(state.quit, true);
|
||||
assert_eq!(state.message, "hello world");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue