mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-10 12:49:18 +00:00
푸는중
This commit is contained in:
parent
36b377587b
commit
8654e318a7
@ -1,7 +1,6 @@
|
||||
// enums1.rs
|
||||
// Make me compile! Execute `rustlings hint enums1` for hints!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Message {
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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)=>(),
|
||||
_=>(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user