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.

Step 1 / 3

Map each Coin to its value in cents with match.

Hints
  • match value { Pattern => result, _ => fallback }.
03_match.rs
Reset to starterCompiled in a sandbox; hidden checks must pass.
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,
    }
}