푸는중

This commit is contained in:
blacktoast 2021-10-08 08:13:34 +00:00
parent 36b377587b
commit 8654e318a7
3 changed files with 17 additions and 6 deletions

View File

@ -1,7 +1,6 @@
// enums1.rs // enums1.rs
// Make me compile! Execute `rustlings hint enums1` for hints! // Make me compile! Execute `rustlings hint enums1` for hints!
// I AM NOT DONE
#[derive(Debug)] #[derive(Debug)]
enum Message { enum Message {

View File

@ -1,7 +1,6 @@
// enums2.rs // enums2.rs
// Make me compile! Execute `rustlings hint enums2` for hints! // Make me compile! Execute `rustlings hint enums2` for hints!
// I AM NOT DONE
#[derive(Debug)] #[derive(Debug)]
enum Message { enum Message {
@ -13,8 +12,6 @@ enum Message {
} }
impl Message { impl Message {
fn call(&self) { fn call(&self) {
println!("{:?}", &self); println!("{:?}", &self);

View File

@ -2,16 +2,23 @@
// Address all the TODOs to make the tests pass! // Address all the TODOs to make the tests pass!
// I AM NOT DONE // I AM NOT DONE
#[derive(Debug)]
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,
}
#[derive(Debug)]
struct Point { struct Point {
x: u8, x: u8,
y: u8, y: u8,
} }
#[derive(Debug)]
struct State { struct State {
color: (u8, u8, u8), color: (u8, u8, u8),
position: Point, position: Point,
@ -37,6 +44,14 @@ 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 variants
println!("{:?}",message);
match message {
Message::ChangeColor((a,b,c))=>{
self.color=(a,b,c);
},
Message::Move(Point)=>(),
_=>(),
}
} }
} }