enum_example: Add default case in match
This commit is contained in:
parent
e53f4ccb53
commit
c2cb93c15f
1 changed files with 5 additions and 0 deletions
|
|
@ -13,6 +13,7 @@ enum Message {
|
||||||
Move { x: i32, y: i32},
|
Move { x: i32, y: i32},
|
||||||
Write(String),
|
Write(String),
|
||||||
ChangeColor(Color),
|
ChangeColor(Color),
|
||||||
|
YetAnotherMessage,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Message {
|
impl Message {
|
||||||
|
|
@ -26,6 +27,7 @@ impl Message {
|
||||||
Message::Move { x, y } => println!("Calling on a move type: {}, {}!", x, y),
|
Message::Move { x, y } => println!("Calling on a move type: {}, {}!", x, y),
|
||||||
Message::Write (s) => println!("Calling on a write type: {}!", s),
|
Message::Write (s) => println!("Calling on a write type: {}!", s),
|
||||||
Message::ChangeColor (c) => println!("Calling on a color type: {:#?}!", c),
|
Message::ChangeColor (c) => println!("Calling on a color type: {:#?}!", c),
|
||||||
|
_ => println!("Default case in a match"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -48,4 +50,7 @@ fn main() {
|
||||||
let msg = Message::ChangeColor(Color(1,2,3));
|
let msg = Message::ChangeColor(Color(1,2,3));
|
||||||
msg.print();
|
msg.print();
|
||||||
msg.call();
|
msg.call();
|
||||||
|
let msg = Message::YetAnotherMessage;
|
||||||
|
msg.print();
|
||||||
|
msg.call();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue