The functions provided fall into a few main types:
- Input functions convert values into result types
- Output functions convert result types back into values
- Transform functions operate on result types
- Predicate functions return booleans
- Collection functions provide an interface to access collections without exceptions.
| Works on | Function | Description |
|---|
| Option | try_pop! | Try to pop! a value from a collection. Also works with Iterators.Stateful. |
| Option | try_get | Try to get a value from a collection |
| Option | try_peek | Try to peek a value from an iterator |
| Option | try_first | Try to get the first value in a collection |
| Option | try_last | Try to get the last value in a collection |
| Macro | Description |
|---|
@unwrap_or | Short-circuiting version of unwrap_or, which allows for the embedding of control statements. |
@try_unwrap | Unwraps a value or bubbles an error upstream. |
@some_if | Evaluates and returns Some if a predicate is satisfied |
@catch_result | Catch an exception and return it as a Result instead |
@if_let | Conditionally unwrap a value inside of a block |
@while_let | Run a loop while successful |
The following operators are overloaded for use with Result types:
| Operator | Description |
|---|
Base.:& | And/all operator, returns the first Err value. Supports closures for lazy evaluation. |
Base.:| | Or/any operator, returns the first Ok value. Supports closures for lazy evaluation. |
Base.:! | Flips Ok and Error values, turning Result{T, E} into Result{E, T}. |
In addition, three new operators are introduced for use with Results and Options:
| Operator | Description |
|---|
← | try_map: applies a function to the inside of a result type. |
→ | Argument-flipped version of try_map. |
⊗ | and_then/monadic bind: connects fallable functions together and returns errors early. |
These new operators are not exported by default.