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.
Classify a point by which axis it sits on in classify.
Hints
- Tuples match directly:
(0, 0) => ..., and_means 'anything'.
Reveal solution
fn classify(p: (i32, i32)) -> &'static str {
match p {
(0, 0) => "origin",
(_, 0) => "x-axis",
(0, _) => "y-axis",
_ => "elsewhere",
}
}