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.
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"
};
OptionIterator | An iterator that yields either one or zero elements |
Option | The option type |
AsOption | A generic trait for converting a value to a |
IntoOption | A generic trait for converting a value to a |
ToOption | A generic trait for converting a value to a |
Prefix searches with a type followed by a colon (e.g.
fn:
) to restrict the search to a given type.
Accepted types are: fn
, mod
,
struct
(or str
), enum
,
trait
, typedef
(or
tdef
).