---
source: https://iinventedlight.com/library/notes/rust-match.md
title: "The match control flow construct in Rust"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT or Apache-2.0 (rust-lang/book; Copyright (c) 2010 The Rust Project Developers; https://github.com/rust-lang/book/blob/main/LICENSE-MIT); MIT or Apache-2.0 (rust-lang/rust-by-example; Copyright (c) 2014 Jorge Aparicio; https://github.com/rust-lang/rust-by-example/blob/master/LICENSE-MIT); prose restates or closely paraphrases cited source lines"
license_family: rust-mit
rule_check: "needs rule check (family not in auto-publish rule; check.mjs auto-approves only usgov and arxiv-ccby)"
attribution: "Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, The match Control Flow Construct - The Rust Programming Language, MIT or Apache-2.0 (rust-lang/book; Copyright (c) 2010 The Rust Project Developers; https://github.com/rust-lang/book/blob/main/LICENSE-MIT); Rust by Example, match - Rust By Example, MIT or Apache-2.0 (rust-lang/rust-by-example; Copyright (c) 2014 Jorge Aparicio; https://github.com/rust-lang/rust-by-example/blob/master/LICENSE-MIT)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: Rust"
tags: ['rust', 'match', 'pattern-matching']
sources:
  - id: S1
    title: "The match Control Flow Construct - The Rust Programming Language"
    publisher: The Rust Programming Language
    url: https://doc.rust-lang.org/book/ch06-02-match.html
    accessed: 2026-11-04
    license: "MIT or Apache-2.0 (rust-lang/book; Copyright (c) 2010 The Rust Project Developers; https://github.com/rust-lang/book/blob/main/LICENSE-MIT)"
  - id: S2
    title: "match - Rust By Example"
    publisher: Rust by Example
    url: https://doc.rust-lang.org/rust-by-example/flow_control/match.html
    accessed: 2026-11-04
    license: "MIT or Apache-2.0 (rust-lang/rust-by-example; Copyright (c) 2014 Jorge Aparicio; https://github.com/rust-lang/rust-by-example/blob/master/LICENSE-MIT)"
---
# The match control flow construct in Rust

**Answer:** Rust has an extremely powerful control flow construct called match that allows you to compare a value against a series of patterns and then execute code based on which pattern matches. (S1)

## Why it is powerful

- The power of match comes from the expressiveness of the patterns and the fact that the compiler confirms that all possible cases are handled. (S1)
- Values go through each pattern in a match, and at the first pattern the value "fits," the value falls into the associated code block to be used during execution. (S1)
- Another useful feature of match arms is that they can bind to the parts of the values that match the pattern. (S1)

## Compared with switch

- Rust provides pattern matching via the match keyword, which can be used like a C switch. (S2)
- The first matching arm is evaluated and all possible values must be covered. (S2)

## Claims
- id: C1
  claim: match compares a value against patterns.
  source: S1
  evidence: "allows you to compare a value against a series of patterns and then execute"
- id: C2
  claim: The compiler checks all cases.
  source: S1
  evidence: "patterns and the fact that the compiler confirms that all possible cases are"
- id: C3
  claim: Arms can bind parts of values.
  source: S1
  evidence: "values that match the pattern. This is how we can extract values out of enum"
- id: C4
  claim: match is like a C switch.
  source: S2
  evidence: "which can be used like"

## Sources
- [S1] The match Control Flow Construct - The Rust Programming Language. The Rust Programming Language. https://doc.rust-lang.org/book/ch06-02-match.html . License: MIT or Apache-2.0 (rust-lang/book; Copyright (c) 2010 The Rust Project Developers; https://github.com/rust-lang/book/blob/main/LICENSE-MIT). Accessed 2026-11-04.
- [S2] match - Rust By Example. Rust by Example. https://doc.rust-lang.org/rust-by-example/flow_control/match.html . License: MIT or Apache-2.0 (rust-lang/rust-by-example; Copyright (c) 2014 Jorge Aparicio; https://github.com/rust-lang/rust-by-example/blob/master/LICENSE-MIT). Accessed 2026-11-04.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
