Module std::option

Operations on the ubiquitous Option type.

Type Option represents an optional value.

Every Option<T> value can either be Some(T) or None. Where in other languages you might use a nullable type, in Rust you would use an option type.

Options are most commonly used with pattern matching to query the presence of a value and take action, always accounting for the None case.

Example

let msg = Some(~"howdy");

// Take a reference to the contained string
match msg {
    Some(ref m) => io::println(*m),
    None => ()
}

// Remove the contained string, destroying the Option
let unwrapped_msg = match msg {
    Some(m) => m,
    None => ~"default message"
};

Structs

OptionIterator

An iterator that yields either one or zero elements

Enums

Option

The option type

Traits

AsOption

A generic trait for converting a value to a Option

IntoOption

A generic trait for converting a value to a Option

ToOption

A generic trait for converting a value to a Option