← All notes

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

Sources

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

Permanent ID: iil:note:febnkw8n

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.},
}

Markdown

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.

All artifact files (JSON index)

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.