This commit is contained in:
liruifengv 2022-11-05 16:06:35 +08:00
parent 2f8e64d118
commit 0b3e8d79f9
4 changed files with 22 additions and 10 deletions

View File

@ -1,11 +1,12 @@
// 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() {

View File

@ -1,11 +1,16 @@
// 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: i32,
y: i32,
},
Echo(String),
ChangeColor(i32, i32, i32),
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
Move(Point),
Echo(String),
ChangeColor((u8, u8, u8)),
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::Echo(string) => println!("{}", string),
Message::Move(point) => self.position = point,
Message::ChangeColor(color) => self.color = color,
Message::Quit => self.quit = true,
}
}
}

View File

@ -33,7 +33,7 @@ mod my_module {
Command::Uppercase => content.to_uppercase(),
Command::Trim => content.trim().to_string(),
Command::Append(n) => format!("{}{}", content, "bar".repeat(*n))
}
}
}).collect()
}
}