if let: concise control flow for one pattern
Answer: The if let syntax lets you combine if and let in a less verbose way. You handle values that match one pattern while ignoring the rest.
The book form
The book introduces if let as a less verbose way to handle values that match one pattern.
The same page also covers let...else as concise control flow.
The following code behaves the same as the match in the listing: if let Some(max) = config_max.
Rust by Example
Matching enums with match can feel awkward in some use cases.
For those cases if let is cleaner, and it also lets you specify various failure options.
Read the construct as: if let destructures the value into the pattern, then evaluate the block.
See also
Claims
- id: C1 claim: if let combines if and let to handle one pattern and ignore the rest. source: S1 evidence: "combine if and let into a less verbose way"
- id: C2 claim: The book also presents let...else as related concise control flow. source: S1 evidence: "if let and let...else"
- id: C3 claim: if let is cleaner than a full match for some enum cases. source: S2 evidence: "if let is cleaner for this use case"
- id: C4 claim: if let can specify various failure options. source: S2 evidence: "allows various failure options to be specified"
Sources
- [S1] Concise Control Flow with if let and let...else. The Rust Programming Language. https://doc.rust-lang.org/book/ch06-03-if-let.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.
- [S2] if let. Rust by Example. https://doc.rust-lang.org/rust-by-example/flow_control/if_let.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, Concise Control Flow with if let and let...else; Rust by Example, if let. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, Concise Control Flow with if let and let...else; Rust by Example, if let. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers.
Cite this
iinventedlight. 2026. "if let: concise control flow for one pattern." iinventedlight Library, iil:note:febnkw8n, version of 2026-11-23. https://iinventedlight.com/library/notes/rust-if-let/. License: CC-BY-4.0.
@misc{iil_note_febnkw8n,
author = {{iinventedlight}},
title = {{if let: concise control flow for one pattern}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/rust-if-let/},
note = {Permanent ID iil:note:febnkw8n. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- rust-if-let.schema.json (schema; CC-BY-4.0)
- rust-if-let.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/rust-if-let.md.