Rust 1.99 (2024 edition) reference · 4 entries
Rust Option and Result
Handle missing values and errors: unwrap_or, map, and_then, the ? operator, map_err and collecting Results.
| Name | Description | Since |
|---|---|---|
Option::unwrap_or and friends |
Get the value out of an Option with a default, a computed default, or the type's default instead of panicking with unwrap. | |
Option::map, and_then and filter |
Transform the value inside an Option without unwrapping it, chain optional steps, or keep it only if a condition holds. | |
The ? operator |
Propagate errors from functions returning Result or Option: unwrap Ok values and return early on Err. | |
Result::map_err, unwrap_or_else and ok |
Convert or recover from errors: change the error type, fall back to a value, or discard the error as an Option. |