- expect(msg: &str) → T: Returns value if
Some, panics with custom message ifNone
Panics. Returning T instead of Option<T>
- unwrap() → T: Returns value if
Some, panics ifNone - unwrap_or(T) → T: Returns value if
Some, otherwise default value - unwrap_or_else(() → T) → T: Like
unwrap_or, but with closure - unwrap_or_default() → T: Returns value if
Some, otherwise default value for type T (requiresDefaulttrait)
Modify Option<T>. Closure returns U
- map(T → U) → Option<U>: Transforms
Some(T)toSome(U)with closure,NonestaysNone - map_or(U, T → U) → U: Applies closure to
Some(T)to get U, or returns default U ifNone - map_or_else(() → U, T → U) → U: Applies closure G to
Some(T)to get U, or closure F to get U ifNone
Modify Option<T>. Closure returns Option
- and_then(T → Option<U>) → Option<U>: Chains operation, applying closure to
Some(T)to produce anotherOption - filter(&T → bool) → Option<T>: Returns
Some(T)if closure returnstrue, otherwiseNone - flatten() → Option<U>: Flattens
Option<Option<U>>intoOption<U> - or_else(() → Option<T>) → Option<T>: Returns
Someif present, otherwise applies closure
Convert Option<T> to Result<T, E> using:
- ok_or(E) → Result<T, E>: Returns
Ok(T)ifSome, otherwiseErr(E)with provided error. - ok_or_else(() → E) → Result<T, E>: Like
ok_or, but error is computed by closure ifNone.
Combine
- and(Option<U>) → Option<U>: Returns input
Optionif both areSome, otherwiseNone - or(Option<T>) → Option<T>: Returns first
Some, otherwise lastNone
Check
- is_some() → bool: Returns
trueifSome, otherwisefalse - is_none() → bool: Returns
trueifNone, otherwisefalse - contains(U) → bool: Returns
trueifSomeand value equals U, otherwisefalse