pub trait IntoContext {
// Required method
fn into_ctx<C2: ThinContext>(self) -> Report<C2>;
}Expand description
Trait for converting error reports from one context type to another.
Required Methods§
Sourcefn into_ctx<C2: ThinContext>(self) -> Report<C2>
fn into_ctx<C2: ThinContext>(self) -> Report<C2>
Convert this error report to use a different context type.
This method transforms a Report<C> into a Report<C2> with C2 being a ThinContext.
When the std::any::TypeId of C and C2 is the same, only a Location is attached.
§Example
use bigerror::{IntoContext, ThinContext, Report, NotFound, ResultIntoContext, DbError};
#[derive(ThinContext)]
struct ServiceError;
fn fetch_user_data() -> Result<String, Report<ServiceError>> {
// 1. Simulate database operation that returns `NotFound`
let db_result: Result<String, Report<NotFound>> =
Err(NotFound::attach_kv("user_id", 123));
// 2. Convert `NotFound` to `DbError`
let database_result: Result<String, Report<DbError>> =
db_result.into_ctx();
// 3. Convert `DbError` into `ServiceError`
database_result.into_ctx()
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.