7 From panic to result: Error handling

This chapter covers

  • Understanding the difference between pure and impure functions
  • Understanding the downsides of breaking control flow
  • Using Result for better error handling
  • Writing macros to manipulate function signatures and return values
  • Mutating the received TokenStream as an alternative to creating a new one
  • Creating better error messages with syn::Error or proc_macro_error

Until now, most of our code has focused on structs and enums, with very basic error handling. All of that changes right now! In this chapter, we will manipulate functions, changing panics into Results, which is a better and more idiomatic way of handling errors in Rust. This is a useful segue into seeing how we can manipulate ...

Get Write Powerful Rust Macros now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.