Skip to main content

define_err_macro

Macro define_err_macro 

Source
macro_rules! define_err_macro {
    ($macro_name:ident, $error:ty, $error_type:ty, $error_type_ident:ident, $doc:expr) => { ... };
}
Expand description

Defines a crate-local error creation macro that can be re-exported from a module.

This avoids using the paste crate and keeps the implementation simple. Each error module should use this to define their own specialized macro.

This helper macro (define_err_macro!) is #[macro_export] so it can be invoked from sibling crates. The generated macro itself is crate-local, so callers can re-export it through a crate prelude without creating a root-level exported macro and without triggering macro_expanded_macro_exports_accessed_by_absolute_paths.

§Examples

// In models/src/error.rs:
define_err_macro!(
    model_err,
    ModelError,
    ModelErrorType,
    ModelErrorType,
    "Create a ModelError."
);