푸는중

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
// Make me compile! Execute `rustlings hint enums1` for hints!
// I AM NOT DONE
#[derive(Debug)]
enum Message {

View File

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

View File

@ -2,16 +2,23 @@
// Address all the TODOs to make the tests pass!
// I AM NOT DONE
#[derive(Debug)]
enum Message {
// TODO: implement the message variant types based on their usage below
}
ChangeColor((u8,u8,u8)),
Echo(String),
Move(Point),
Quit,
}
#[derive(Debug)]
struct Point {
x: u8,
y: u8,
}
#[derive(Debug)]
struct State {
color: (u8, u8, u8),
position: Point,
@ -37,6 +44,14 @@ impl State {
fn process(&mut self, message: Message) {
// 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)=>(),
_=>(),
}
}
}