How to use thiserror crate in Rust error derive

Use the thiserror derive macro to automatically implement error traits and define display messages for custom error enums in Rust.

Use the thiserror::Error derive macro on your error enum to automatically implement std::error::Error and define display messages via attributes.

use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {
    #[error("No config for '{0}'")]
    NoConfig(String),

    #[error(transparent)]
    Mdbook(#[from] mdbook_preprocessor::errors::Error),
}

This pattern allows you to define custom error messages with placeholders and transparently wrap other errors using #[from] for automatic conversion.