- expect(msg: &str): Like
unwrap, but with custom err msg - expect_none(msg: &str): Panics with custom message if
Err, expectsNoneforOption(used withResult<Option<T>, E>)
Panics. Returning T instead of Result<T, E>
- unwrap(): Return value if
Ok, otherwise panics - unwrap_or(T) → T: Return value if
Ok, otherwise default value - unwrap_or_else(() → T) → T: Like
unwrap_or, but with closure - unwrap_or_default() → T: Returns value if
Ok, otherwise default value for type T (requiresDefaulttrait)
Modify Result<T, E>. Closure returns U
- map(T → U) → Result<U, E>: Transform
Ok(T)toOk(U)with a closure - map_err(E → U) → Result<T, U>: Transform
Err(T)toErr(U)with a closure - map_or(U, T → U) → U: Applies closure to
Ok(T)to get U, or returns default U ifErr - map_or_else(E → U, T → U) → U: Applies closure G to
Ok(T)to get U, or closure F toErr(E)to get U
Modify Result<T, E>. Closure returns Result
- and_then(T → Result<U, E>) → Result<U, E>: Chains operation, applying a closure to
Ok(T)to produce anotherResult - or_else(E → Result<U, E>) → Result<U, E>: Like
and_then, but forErr(T) - flatten() → Result<U, E>: Flattens
Result<Result<U, E>, E>intoResult<U, E> - transpose() → Option<Result<T, E>>: Converts
Result<Option<T>, E>toOption<Result<T, E>>
Combine
- and(Result<U, E>) → Result<U, E>: Returns input
Resultif both areOk, otherwise firstErr - or(Result<T, F>) → Result<T, F>: Returns first
Ok, otherwise lastErr
Check
- is_ok(): Returns
trueifOk, otherwisefalse - is_err(): Returns
trueifErr, otherwisefalse - contains(U) → bool: Returns
trueifOkand value equals U, otherwisefalse - contains_err(U) → bool: Returns
trueifErrand error equals U, otherwisefalse