Skip to main content

impl_context_error

Macro impl_context_error 

Source
macro_rules! impl_context_error {
    ($error_type:ident) => { ... };
    ($vis:vis $error_type:ident) => { ... };
}
Expand description

Implement context-aware error handling for a custom type.

This macro generates a struct definition and all necessary trait implementations to make a type work with expect_error.

§Generated Structure

The macro generates a struct with these fields:

  • message: Cow<'static, str> - The error message
  • source: Option<Box<dyn Error + Send + Sync>> - The underlying error
  • location: Option<&'static Location> - Where the error was created

§Usage

§Basic Usage (crate-private visibility)

use scoped_error::impl_context_error;

impl_context_error!(MyError);
// Generates: pub(crate) struct MyError { ... }

§Custom Visibility

use scoped_error::impl_context_error;

impl_context_error!(pub MyError);
// Generates: pub struct MyError { ... }

§Generated Implementations

The macro generates:

  • #[derive(Debug)]
  • std::error::Error (with source() method)
  • std::fmt::Display (includes location when available)
  • From<(Cow<'static, str>, Frame)> (for use with expect_error)