Working With Rust Result - Summary - Part 14
If you’ve made it this far, you’re probably overwhelmed by all the different methods and their uses! It helps to try and learn to use them one at a time; as and when needed. The following table summarises which method you would use under different circumstances.
What do you want to do? | Method to use |
---|---|
Create a Result
|
|
Get both values out of a Result
|
|
Run a function on the value inside Ok
|
|
Run a function on the value inside Err
|
|
Get the value inside Ok
|
|
Get the value inside Ok with fallback
|
|
Get the value inside Err
|
|
Get the value inside Err with fallback
|
|
Combine two Result s that are Ok
|
|
Combine two Result s that are Err
|
|
Convert Ok to Option as Some
|
|
Convert Err to Option as Some
|
|
Convert Result<Option> to Option<Result>
|
|
Test for Ok
|
|
Test for Err
|
|
Test for Ok and run a predicate
|
|
Test for Err and run a predicate
|
|
I hope this somewhat lengthy series helped you learn some more about Rust’s Result
type. If you found any errors or omissions or found this useful, please leave a comment.
- Back to TOC