The Option Type for Absent Values

Updated

October 31, 2026

The Option Type for Absent Values

Rust has no null or nil. Absent values are explicitly represented with Option<T>:

fn find_desk(number: u32) -> Option<&'static str> {
    if number == 1 {
        Some("Front Reception")
    } else {
        None
    }
}

fn main() {
    let desk = find_desk(1);
    println!("Found desk: {:?}", desk.unwrap_or("Unassigned"));
}