pub trait ThinContext{
const VALUE: Self;
// Provided methods
fn report<C: Context>(ctx: C) -> Report<Self> { ... }
fn attach_with<A>(attachment: impl FnOnce() -> A) -> Report<Self>
where A: Display { ... }
fn attach<A>(value: A) -> Report<Self>
where A: Display { ... }
fn attach_dbg<A>(value: A) -> Report<Self>
where A: Debug { ... }
fn attach_kv<K, V>(key: K, value: V) -> Report<Self>
where K: Display,
V: Display { ... }
fn attach_kv_dbg<K, V>(key: K, value: V) -> Report<Self>
where K: Display,
V: Debug { ... }
fn attach_field<S: Display>(key: &'static str, status: S) -> Report<Self> { ... }
fn expected_actual<A: Display>(expected: A, actual: A) -> Report<Self> { ... }
fn attach_ty_val<A: Display>(value: A) -> Report<Self> { ... }
fn attach_ty_dbg<A: Debug>(value: A) -> Report<Self> { ... }
fn attach_ty<A>() -> Report<Self> { ... }
fn attach_ty_status<A: Send + Sync + 'static>(
status: impl Display,
) -> Report<Self> { ... }
}Expand description
A trait for zero-sized error types that provides convenient error creation methods.
ThinContext extends the functionality of error_stack::Context by providing
static methods for creating error reports with attachments. This trait is ideally
used for zero-sized error types or types that hold only 'static references.
§Example
use bigerror::{ThinContext, Report};
#[derive(ThinContext)]
pub struct MyError;
// Create an error with an attachment
let error: Report<MyError> = MyError::attach("Something went wrong");Required Associated Constants§
Provided Methods§
Sourcefn report<C: Context>(ctx: C) -> Report<Self>
fn report<C: Context>(ctx: C) -> Report<Self>
Create a new error report by converting from another context type.
§Arguments
ctx- The source context to convert from
Sourcefn attach_with<A>(attachment: impl FnOnce() -> A) -> Report<Self>where
A: Display,
fn attach_with<A>(attachment: impl FnOnce() -> A) -> Report<Self>where
A: Display,
Create an error report with an attachment computed by a closure.
This is useful for lazy evaluation of expensive attachment computations.
Sourcefn attach<A>(value: A) -> Report<Self>where
A: Display,
fn attach<A>(value: A) -> Report<Self>where
A: Display,
Create an error report with a displayable attachment.
Sourcefn attach_dbg<A>(value: A) -> Report<Self>where
A: Debug,
fn attach_dbg<A>(value: A) -> Report<Self>where
A: Debug,
Create an error report with a debug-formatted attachment.
The attachment will be formatted using Debug instead of Display.
Sourcefn attach_kv<K, V>(key: K, value: V) -> Report<Self>
fn attach_kv<K, V>(key: K, value: V) -> Report<Self>
Create an error report with a key-value pair attachment.
Sourcefn attach_kv_dbg<K, V>(key: K, value: V) -> Report<Self>
fn attach_kv_dbg<K, V>(key: K, value: V) -> Report<Self>
Create an error report with a key-value pair where the value is debug-formatted.
Sourcefn attach_field<S: Display>(key: &'static str, status: S) -> Report<Self>
fn attach_field<S: Display>(key: &'static str, status: S) -> Report<Self>
Create an error report with a field attachment.
This represents a property or field of a data structure and its status.
Sourcefn expected_actual<A: Display>(expected: A, actual: A) -> Report<Self>
fn expected_actual<A: Display>(expected: A, actual: A) -> Report<Self>
Create an error report showing expected vs actual values.
Useful for validation errors where you want to show what was expected versus what was actually received.
Sourcefn attach_ty_val<A: Display>(value: A) -> Report<Self>
fn attach_ty_val<A: Display>(value: A) -> Report<Self>
Create an error report with a type-value pair attachment.
The key will be the type name and the value will be the provided value.
Sourcefn attach_ty_dbg<A: Debug>(value: A) -> Report<Self>
fn attach_ty_dbg<A: Debug>(value: A) -> Report<Self>
Create an error report with a type-value pair where the value is debug-formatted.
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.