mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-09 12:19:18 +00:00
finished enums
This commit is contained in:
parent
cf46c715c3
commit
3ffef7bbb4
@ -1,11 +1,12 @@
|
||||
// enums1.rs
|
||||
// Make me compile! Execute `rustlings hint enums1` for hints!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Message {
|
||||
// TODO: define a few types of messages as used below
|
||||
Quit,
|
||||
Echo,
|
||||
Move,
|
||||
ChangeColor
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
// enums2.rs
|
||||
// Make me compile! Execute `rustlings hint enums2` for hints!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Message {
|
||||
// TODO: define the different variants used below
|
||||
Quit,
|
||||
Echo(String),
|
||||
Move{x:i32, y:i32},
|
||||
ChangeColor(u8, u8, u8)
|
||||
}
|
||||
|
||||
impl Message {
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
// enums3.rs
|
||||
// Address all the TODOs to make the tests pass!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
enum Message {
|
||||
// TODO: implement the message variant types based on their usage below
|
||||
Quit,
|
||||
Echo(String),
|
||||
Move(Point),
|
||||
ChangeColor((u8, u8, u8))
|
||||
}
|
||||
|
||||
struct Point {
|
||||
@ -36,6 +37,15 @@ impl State {
|
||||
}
|
||||
|
||||
fn process(&mut self, message: Message) {
|
||||
match message{
|
||||
Message::Quit => self.quit(),
|
||||
Message::Move(p) => { self.move_position(p) },
|
||||
Message::Echo(s) => self.echo(s),
|
||||
Message::ChangeColor((r, g, b)) => {
|
||||
self.change_color((r, g, b));
|
||||
}
|
||||
|
||||
}
|
||||
// TODO: create a match expression to process the different message variants
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user