std-type

Option<T> — optional values

Option wraps a present value in Some or indicates absence with None. A match can consume the payload or borrow it, depending on the expression and pattern. Choose the inner type explicitly when inference has insufficient context. Expected stdout (not executed): 15% Common mistake: Trying to read the inner T directly from an Option<T>.

Formal Syntax & Structure

rust syntaxrust
enum Option<T> { None, Some(T) }

Working Example

Example Snippetrust
fn main() {    let discount = Some(15u32);    match discount { Some(n) => println!("{n}%"), None => println!("No discount") }}
Rust Reference