mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-05 02:09:18 +00:00
Fix if statement in if1.rs and implement message variants in enums3.rs
This commit is contained in:
parent
cac63c180d
commit
23a2a21036
@ -8,7 +8,7 @@ pub fn bigger(a: i32, b: i32) -> i32 {
|
|||||||
// - another function call
|
// - another function call
|
||||||
// - additional variables
|
// - additional variables
|
||||||
if a > b {
|
if a > b {
|
||||||
return a > b
|
return a
|
||||||
}
|
}
|
||||||
b
|
b
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,10 +5,12 @@
|
|||||||
// Execute `rustlings hint enums3` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint enums3` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
// 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 {
|
||||||
@ -44,6 +46,14 @@ impl State {
|
|||||||
// TODO: create a match expression to process the different message variants
|
// TODO: create a match expression to process the different message variants
|
||||||
// Remember: When passing a tuple as a function argument, you'll need extra parentheses:
|
// Remember: When passing a tuple as a function argument, you'll need extra parentheses:
|
||||||
// fn function((t, u, p, l, e))
|
// fn function((t, u, p, l, e))
|
||||||
|
match message {
|
||||||
|
Message::ChangeColor(r, g, b) => self.change_color((r, g, b)),
|
||||||
|
Message::Echo(s) => self.echo(s),
|
||||||
|
Message::Move(point) => self.move_position(point),
|
||||||
|
Message::Quit => self.quit(),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user