How does Option work in Rust

Option is an enum with Some(T) and None variants used to safely represent values that may or may not exist.

Option is an enum that represents an optional value, containing either Some(T) for a value or None for absence. You handle it by matching on its variants to extract the value or handle the missing case.

fn plus_one(x: Option<i32>) -> Option<i32> {
    match x {
        None => None,
        Some(i) => Some(i + 1),
    }
}

let five = Some(5);
let six = plus_one(five);
let none = plus_one(None);