Use the `thiserror` crate to define custom error enums with automatic `std::error::Error` implementation via derive macros.
Add thiserror to your dependencies and derive the Error trait on your enum to automatically implement std::error::Error.
[dependencies]
thiserror = "1.0.60"
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("No config for '{0}'")]
NoConfig(String),
#[error(transparent)]
Mdbook(#[from] mdbook_preprocessor::errors::Error),
}
The thiserror crate is a tool that makes creating custom error types in Rust much easier. Instead of writing repetitive code to make your errors work with the rest of the language, you just add a small attribute to your error list. It's like having a template that automatically fills in the boring parts so you can focus on what the error actually means.