Option: a value that may be Some or None
Answer: Option is an enum with two variants. Some wraps a value. None indicates failure or lack of value. Use Option to catch the failure of some parts of a program instead of calling panic!. Unwrapping a Some variant will extract the value wrapped. Unwrapping a None variant will panic.
The two variants
When part of a program may fail, Option lets you catch that failure instead of calling panic!.
The enum has two variants.
None indicates failure or lack of value.
Some(value) is a tuple struct that holds a value of type T.
Like other enums, you can match on an Option.
unwrap on Some takes out the wrapped value. unwrap on None panics.
A None binding needs a type annotation.
How the standard library describes it
Type Option stands for an optional value.
Option values can be pattern matched, just like other enums.
The Some variant contains a value. The None variant does not.
Typical uses include initial values, returns from partial functions, and optional struct fields.
Code often pairs Option with pattern matching so the None case is always handled.
See also
Claims
- id: C1 claim: Option can catch a failure instead of calling panic!. source: S2 evidence: "instead of calling"
- id: C2 claim: None indicates failure or lack of value. source: S2 evidence: "indicate failure or lack of value"
- id: C3 claim: Some wraps a value of type T. source: S2 evidence: "wraps a"
- id: C4 claim: Unwrapping None panics. source: S2 evidence: "Unwrapping a
Nonevariant will"
- id: C5 claim: Every Option is either Some with a value, or None. source: S1 evidence: "either Some and contains a value, or None"
Sources
- [S1] std::option. Rust Standard Library. https://doc.rust-lang.org/std/option/index.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.
- [S2] Option. Rust By Example. https://doc.rust-lang.org/rust-by-example/std/option.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: Rust Standard Library, std::option; Rust By Example, Option. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust/master/COPYRIGHT). 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: Rust Standard Library, std::option; Rust By Example, Option. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust/master/COPYRIGHT). 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. "Option: a value that may be Some or None." iinventedlight Library, iil:note:fdfyy9mb, version of 2026-11-23. https://iinventedlight.com/library/notes/rust-option/. License: CC-BY-4.0.
@misc{iil_note_fdfyy9mb,
author = {{iinventedlight}},
title = {{Option: a value that may be Some or None}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/rust-option/},
note = {Permanent ID iil:note:fdfyy9mb. 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-option.schema.json (schema; CC-BY-4.0)
- rust-option.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-option.md.