← All Exercises

Pattern Matching with Enums

basicrust~15min

Background

Pattern matching is Rust powerful control flow construct for destructuring and matching.

Problem

Match on enum variants with associated data using pattern matching with guards.

Input

Enum values to match

Output

Branch-specific handling

Sample tests

Sample 1

Input: match Option::Some(42)
Expected: handles Some case

Your solution

Learning objective

Learn pattern matching and exhaustive enum handling