This commit is contained in:
enforcer007 2022-11-13 13:21:52 +05:30
parent ea13bc5749
commit 3b06c0dd76
3 changed files with 18 additions and 11 deletions

View File

@ -1,13 +1,13 @@
// enums1.rs
// No hints this time! ;)
// I AM NOT DONE
#[derive(Debug)]
enum Message {
// TODO: define a few types of messages as used below
Quit,
Echo,
Move,
ChangeColor,
}
fn main() {
println!("{:?}", Message::Quit);
println!("{:?}", Message::Echo);

View File

@ -1,11 +1,12 @@
// enums2.rs
// Execute `rustlings hint enums2` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
#[derive(Debug)]
enum Message {
// TODO: define the different variants used below
Move { x: u8, y: u8 },
Echo(String),
ChangeColor(u8, u8, u8),
Quit,
}
impl Message {

View File

@ -2,10 +2,11 @@
// Address all the TODOs to make the tests pass!
// Execute `rustlings hint enums3` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
enum Message {
// TODO: implement the message variant types based on their usage below
ChangeColor((u8, u8, u8)),
Echo(String),
Move(Point),
Quit,
}
struct Point {
@ -37,7 +38,12 @@ impl State {
}
fn process(&mut self, message: Message) {
// TODO: create a match expression to process the different message variants
match message {
Message::Quit => self.quit(),
Message::ChangeColor((x, y, z)) => self.change_color((x, y, z)),
Message::Move(x) => self.move_position(x),
Message::Echo(x) => self.echo(x),
}
}
}