O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Summary

Here's what you should remember from this chapter:

  • Error handling in Rust is explicit: operations that could fail have a two-part return value via the Result or Option generic types
  • You must handle errors in some way, either by deconstructing the Result/Option values by a match statement, or by using the helper methods or macros
  • You should usually opt for handling errors properly, that is, not resorting to operations that panic on failures
  • Use the unwrapping methods or panicking when errors would be programming errors or so fatal that recovery would be impossible
  • Panics are mostly non-recoverable, which means that they crash your thread
  • Use the standard Error trait for your own error types

The next chapter will be about Rust's somewhat ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required