#[allow(dead_code)]
pub enum Coin {
Penny(u8),
Cent(u8),
Ten(u8),
TwentyFive(u8),
}
#[allow(dead_code, unused_variables)]
fn is_valid(coin: Option<&Coin>) {
match coin {
Some(_coin) => println!("valid money"),
None => println!("invalid money"),
}
}
#[allow(dead_code)]
impl Coin {
fn check_money(&self) {
match self {
Self::Penny(value) => println!("It's penny, total worth: {}", value),
Self::Ten(value) => println!("It's ten, total worth: {}", value),
Self::Cent(value) => println!("It's cent, total worth: {}", value),
Self::TwentyFive(value) => println!("It's twenty five, total worth: {}", value),
}
}
}
#[allow(dead_code, unused_variables)]
pub fn control_flow() {
let money1 = Coin::Penny(20);
let money2 = Coin::TwentyFive(25);
is_valid(Some(&money1));
is_valid(Some(&money2));
money1.check_money();
money2.check_money();
}
#[allow(dead_code, unused_variables)]
pub fn concise_control_flow() {
let money = Coin::Penny(20);
let money1 = Coin::Cent(100);
if let Coin::Penny(penny) = money {
println!("Money is penny and it's worth is : {}", penny)
} else {
println!("Money is not penny!")
}
}