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 messagesource: Option<Box<dyn Error + Send + Sync>>- The underlying errorlocation: 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(withsource()method)std::fmt::Display(includes location when available)From<(Cow<'static, str>, Frame)>(for use withexpect_error)