Core Beginner
03 Pattern matching
match lets you branch on shape and value at once. Map coins to cents, then classify a point by which axis it sits on.
Map each Coin to its value in cents with match.
Hints
match value { Pattern => result, _ => fallback }.
Reveal solution
enum Coin { Penny, Nickel, Dime, Quarter }
fn value(c: Coin) -> u32 {
match c {
Coin::Penny => 1,
Coin::Nickel => 5,
Coin::Dime => 10,
Coin::Quarter => 25,
}
}