Enums

Rust does not have the concept of null references. All objects are always valid instances of their type. Instead Rust has enums, which can be one of several variants.

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

Rust will force you to handle all variants of an enum.

fn main() {
    let array: Vec<i32> = vec![];

    match array.last() {
        Some(value) => println!("The last value is: {}", value),
        None => println!("The array is empty"),
    }
}