Rust pattern syntax and refutability
Answer: Patterns are refutable or irrefutable. Parameters, let, and for only accept irrefutable patterns.
Match guards and bindings
A match guard adds an if condition after the pattern; both must succeed for the arm to run. The @ operator binds a variable while still testing the value against a pattern.
The Rust Reference calls a pattern refutable when it might fail to match.
Claims
- id: C1 claim: Patterns are either refutable or irrefutable. source: S1 evidence: "Patterns come in two forms: refutable and irrefutable."
- id: C2 claim: let and function parameters require irrefutable patterns. source: S1 evidence: "Function parameters, let statements, and for loops can only accept irrefutable patterns because the program"
- id: C3 claim: A match guard is an additional if condition on a match arm. source: S2 evidence: "a match guard conditional instead. We'll talk about match guards later in the [\"Adding Conditionals"
- id: C4 claim: The at operator creates a variable while testing a pattern. source: S2 evidence: "The at operator @ lets us create a variable that holds a value at the"
- id: C5 claim: A pattern is said to be refutable when it might not match. source: S3 evidence: "A pattern is said to be refutable when it has the possibility of not being"
Sources
- [S1] Refutability: Whether a Pattern Might Fail to Match. The Rust Project (The Rust Programming Language book). https://doc.rust-lang.org/book/ch19-02-refutability.html . License: MIT OR Apache-2.0. Accessed 2026-11-09.
- [S2] Pattern Syntax. The Rust Project (The Rust Programming Language book). https://doc.rust-lang.org/book/ch19-03-pattern-syntax.html . License: MIT OR Apache-2.0. Accessed 2026-11-09.
- [S3] Patterns - The Rust Reference. The Rust Reference (rust-lang/reference). https://doc.rust-lang.org/reference/patterns.html . License: MIT OR Apache-2.0. Accessed 2026-11-09.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources and notices: The Rust Programming Language book (rust-lang/book): Copyright (c) 2010 The Rust Project Developers; MIT OR Apache-2.0, used under MIT (https://github.com/rust-lang/book/blob/main/LICENSE-MIT). The Rust Reference (rust-lang/reference): Copyright (c) 2010 The Rust Project Developers; MIT OR Apache-2.0, used under MIT (https://github.com/rust-lang/reference/blob/master/LICENSE-MIT). Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Rust book + Rust Reference Patterns (MIT OR Apache-2.0). Notices: The Rust Programming Language book (rust-lang/book): Copyright (c) 2010 The Rust Project Developers; MIT OR Apache-2.0, used under MIT (https://github.com/rust-lang/book/blob/main/LICENSE-MIT). The Rust Reference (rust-lang/reference): Copyright (c) 2010 The Rust Project Developers; MIT OR Apache-2.0, used under MIT (https://github.com/rust-lang/reference/blob/master/LICENSE-MIT).
Cite this
iinventedlight. 2026. "Rust pattern syntax and refutability." iinventedlight Library, iil:note:vkdv3n9y, version of 2026-11-09. https://iinventedlight.com/library/notes/rust-pattern-syntax/. License: CC-BY-4.0.
@misc{iil_note_vkdv3n9y,
author = {{iinventedlight}},
title = {{Rust pattern syntax and refutability}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-09},
url = {https://iinventedlight.com/library/notes/rust-pattern-syntax/},
note = {Permanent ID iil:note:vkdv3n9y. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/rust-pattern-syntax.md.