Trying to learning how to use the Rust Result type can be daunting. In this “Working with Rust Result” series of short posts, I hope to make that more approachable. This series is for beginners who are finding it difficult to understand what a Result is and how to use it.

The series is split into fourteen parts as listed below.

  1. What is a Result? - (Construction)
  2. Extracting Values - (Pattern matching, map_or_else, map_or)
  3. Extracting Values That Can Panic - (unwrap, expect)
  4. Making Things Nicer with Fallbacks - (unwrap_or, unwrap_or_else, unwrap_or_default)
  5. Transforming Values - (map)
  6. Combining Results - (and_then, Aligning error types)
  7. Chaining with Map
  8. Combining Results the Question Mark Operator - (The question mark operator, Keep aligning those error values)
  9. Combining Results Some More - (and, or, or_else)
  10. Working with Errors - (map_err, unwrap_err, expect_err)
  11. Conversion to Option - (ok, err, transpose)
  12. Value Tests - (is_ok, is_err, is_ok_and, is_err_and)
  13. Asides - (Functions that return Result in std, Eager vs Laziness)
  14. Summary - (Cheatsheet, Feedback from the review lounge)

Now I know what you’re thinking:

Fourteen posts? You’ve got to be kidding me!

I know it’s a lot of posts. I’ve tried to make each as small as possible with a single focus. I’ve added examples and some diagrams to make it more palatable.

Also don’t feel the need to read the full series at one go. Read as much as you want or choose a topic you want to know more about or are currently struggling with and start there. Be sure to try some of the examples out and experiment with your own changes; That’s the best way to learn.

Jump in at What is a Result?