← All Exercises

Rust Pattern Matching

intermediaterust~15min

Background

Pattern matching is Rust powerful control flow construct, enabling exhaustive and type-safe branching.

Problem

Write a Rust function that classifies an integer using match with ranges, guards, and variable bindings.

Input

An integer to classify.

Output

A string classification: negative, zero, small, medium, or large.

Sample tests

Sample 1

Input: 0
Expected: "zero"

Your solution

Learning objective

Learn match expressions, range patterns, match guards, and exhaustive matching.