mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-11-08 09:09:17 +01:00
enums3: Avoid confusion with parentheses
This commit is contained in:
parent
01b8432d58
commit
708cfef3f7
@ -12,6 +12,7 @@ struct State {
|
|||||||
height: u64,
|
height: u64,
|
||||||
position: Point,
|
position: Point,
|
||||||
message: String,
|
message: String,
|
||||||
|
// RGB color composed of red, green and blue.
|
||||||
color: (u8, u8, u8),
|
color: (u8, u8, u8),
|
||||||
quit: bool,
|
quit: bool,
|
||||||
}
|
}
|
||||||
@ -30,8 +31,8 @@ impl State {
|
|||||||
self.message = s;
|
self.message = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn change_color(&mut self, color: (u8, u8, u8)) {
|
fn change_color(&mut self, red: u8, green: u8, blue: u8) {
|
||||||
self.color = color;
|
self.color = (red, green, blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn quit(&mut self) {
|
fn quit(&mut self) {
|
||||||
@ -39,9 +40,8 @@ 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
|
||||||
// Remember: When passing a tuple as a function argument, you'll need extra parentheses:
|
// variants using the methods defined above.
|
||||||
// e.g. `foo((t, u, p, l, e))`
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ impl State {
|
|||||||
self.message = s;
|
self.message = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn change_color(&mut self, color: (u8, u8, u8)) {
|
fn change_color(&mut self, red: u8, green: u8, blue: u8) {
|
||||||
self.color = color;
|
self.color = (red, green, blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn quit(&mut self) {
|
fn quit(&mut self) {
|
||||||
@ -47,7 +47,7 @@ impl State {
|
|||||||
Message::Resize { width, height } => self.resize(width, height),
|
Message::Resize { width, height } => self.resize(width, height),
|
||||||
Message::Move(point) => self.move_position(point),
|
Message::Move(point) => self.move_position(point),
|
||||||
Message::Echo(s) => self.echo(s),
|
Message::Echo(s) => self.echo(s),
|
||||||
Message::ChangeColor(r, g, b) => self.change_color((r, g, b)),
|
Message::ChangeColor(r, g, b) => self.change_color(r, g, b),
|
||||||
Message::Quit => self.quit(),
|
Message::Quit => self.quit(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user