Derive Macro ModError

Source
#[derive(ModError)]
{
    // Attributes available to this derive:
    #[error_prefix]
    #[error_display]
    #[error_kind]
    #[error_caption]
    #[error_retryable]
    #[error_http_status]
    #[error_exit_code]
}
Expand description

Derive macro for ModError

This macro automatically implements the ForgeError trait and common error handling functionality for a struct or enum, allowing for “lazy mode” error creation with minimal boilerplate.

§Example

use error_forge::ModError;

#[derive(Debug, ModError)]
#[error_prefix("Database")]
pub enum DbError {
    #[error_display("Connection to {0} failed")]
    ConnectionFailed(String),

    #[error_display("Query execution failed: {reason}")]
    QueryFailed { reason: String },

    #[error_display("Transaction error")]
    #[error_http_status(400)]
    TransactionError,
}