How to use thiserror crate in Rust error types

Define custom Rust error enums using the thiserror crate's derive macro and error attribute annotations.

Use the thiserror crate to define an error enum with the #[derive(thiserror::Error)] attribute and annotate variants with #[error(...)] for messages or #[from] for automatic conversion.

use thiserror::Error;

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

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

Add thiserror = "1.0.60" to your Cargo.toml dependencies.