pub trait IntoErrorContext {
// Required method
fn into_error_context(self) -> ErrorContext;
}Expand description
Converts a type into an ErrorContext for error annotation.
This trait is used throughout the error handling pipeline to accept flexible context types when building composable errors.
§Implementing for Custom Types
If you need to use a custom type as error context, you have two options:
-
Use the
impl_error_context!macro for types implementingDisplay:ⓘimpl_error_context!(MyCustomError); -
Implement the trait manually:
use error_rail::{traits::IntoErrorContext, ErrorContext}; struct MyContext { user_id: u64 } impl IntoErrorContext for MyContext { fn into_error_context(self) -> ErrorContext { ErrorContext::metadata("user_id", self.user_id.to_string()) } }
Required Methods§
Sourcefn into_error_context(self) -> ErrorContext
fn into_error_context(self) -> ErrorContext
Converts self into an ErrorContext.
Implementations on Foreign Types§
Source§impl IntoErrorContext for &'static str
impl IntoErrorContext for &'static str
Source§fn into_error_context(self) -> ErrorContext
fn into_error_context(self) -> ErrorContext
Converts a static string slice into a message context.