rust-pattern-matching

Explain Rust pattern matching exhaustiveness, Option/Result handling, and anti-patterns.

Updated May 26, 2026
One-click install
npx skills add https://github.com/adelabdelgawad/rust-fullstack-agents --skill rust-pattern-matching
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-pattern-matching
Source: https://github.com/adelabdelgawad/rust-fullstack-agents/tree/main/plugins/rusty/skills/rust-pattern-matching
Command: npx skills add https://github.com/adelabdelgawad/rust-fullstack-agents --skill rust-pattern-matching

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Pattern matching in Rust is powerful but easy to misuse, leading to non-exhaustive matches, hidden edge cases, and fragile code. This guide helps developers reason about exhaustiveness, correct usage of Option/Result, and the full spectrum of pattern syntax to write safer, idiomatic Rust.

Core Features & Use Cases

  • Exhaustiveness guidance: explains E0004 and how to avoid catch-all arms that mask future variants.
  • Pattern syntax mastery: covers match guards, @ bindings, or-patterns, and binding modes.
  • Anti-pattern detectors: identifies common pitfalls like manual panic in matches and nested pyramids.
  • Learning and reference: serves as a reference for reviewing or learning Rust pattern matching in real-world code.

Quick Start

Ask for a concise, exhaustive Rust pattern-matching guide for your enum or Option to apply immediately.

Frequently Asked Questions about rust-pattern-matching

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix non-exhaustive pattern match errors in Rust?

Non-exhaustive pattern match errors trigger compiler error E0004 when match arms do not cover all enum variants. Use exhaustive matching instead of catch-all arms to ensure future variants are handled explicitly, preventing hidden edge cases and fragile Rust code.

How does if let work compared to match for handling Rust Option and Result?

if let cleanly destructures Option and Result types when you only care about one specific variant, avoiding verbose match syntax. Use let else for early returns, while match enforces exhaustive checking across all potential Rust enum branches.

What are common anti-patterns in Rust pattern matching?

Common Rust pattern matching anti-patterns include manual panics inside match arms and deeply nested if let pyramids. Refactor these by using let else for early returns and applying or-patterns to combine related branches cleanly for safer code.

When should I use match guards and @ bindings in Rust?

Use match guards to filter patterns conditionally within a match arm, and use @ bindings to capture the matched value while simultaneously testing its inner structure. Both enhance pattern syntax for complex Rust enum destructuring.

Can I use exhaustive matching for code review of Rust enum handling?

Yes, exhaustive matching serves as a reference for code review by checking Option and Result handling, verifying binding modes, and identifying anti-patterns. It ensures real-world Rust code handles edge cases safely without catch-all workarounds.