0Pricing
Learn Rust Coding · Lesson

thiserror

Custom error types.

Why Custom Errors?

Libraries should expose meaningful error types so callers can react to specific failures. Writing these by hand means lots of boilerplate. The thiserror crate generates it for you.

Adding thiserror

Add it as a dependency. It is a derive-macro crate with zero runtime cost.

[dependencies]
thiserror = "1.0"

All lessons in this course

  1. Result and the ? Operator
  2. thiserror
  3. anyhow
  4. Error Conversion
← Back to Learn Rust Coding