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 2 / 3

Classify a point by which axis it sits on in classify.

Hints
  • Tuples match directly: (0, 0) => ..., and _ means 'anything'.
03_match.rs
Reset to starterCompiled in a sandbox; hidden checks must pass.
Reveal solution
fn classify(p: (i32, i32)) -> &'static str {
    match p {
        (0, 0) => "origin",
        (_, 0) => "x-axis",
        (0, _) => "y-axis",
        _ => "elsewhere",
    }
}