prelude.Result
Part of prelude.
enum Result
A value, or an explanation of why there isn't one.
Failure is an ordinary value: no exceptions, so a function that can fail says so in its type.
let Result.is_ok (r: Result[T, E]): Bool
Whether this succeeded.
let Result.is_err (r: Result[T, E]): Bool
Whether this failed.
let Result.unwrap_or (r: Result[T, E]) (fallback: T): T
The value, or fallback on failure — DISCARDING the error. Reach for unwrap_or_else when the error should shape the answer.
let Result.unwrap_or_else (r: Result[T, E]) (f: (E) -> T): T
The value, or the result of calling f with the error. The recovery that gets to see what went wrong.
let Result.map (r: Result[T, E]) (f: (T) -> U): Result[U, E]
Transforms the value on success, leaving an error untouched.
let Result.map_err (r: Result[T, E]) (f: (E) -> F): Result[T, F]
Transforms the ERROR, leaving a success untouched. For adding context to a failure on its way up.
let Result.and_then (r: Result[T, E]) (f: (T) -> Result[U, E]): Result[U, E]
Chains an operation that may itself fail, stopping at the first error. The flat version of map over a fallible step.