ThinContext

Trait ThinContext 

Source
pub trait ThinContext
where Self: Sized + Context,
{ 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§

Source

const VALUE: Self

The singleton value for this zero-sized error type.

Provided Methods§

Source

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
Source

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.

Source

fn attach<A>(value: A) -> Report<Self>
where A: Display,

Create an error report with a displayable attachment.

Source

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.

Source

fn attach_kv<K, V>(key: K, value: V) -> Report<Self>
where K: Display, V: Display,

Create an error report with a key-value pair attachment.

Source

fn attach_kv_dbg<K, V>(key: K, value: V) -> Report<Self>
where K: Display, V: Debug,

Create an error report with a key-value pair where the value is debug-formatted.

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn attach_ty<A>() -> Report<Self>

Create an error report with just a type attachment.

Source

fn attach_ty_status<A: Send + Sync + 'static>( status: impl Display, ) -> Report<Self>

Create an error report with a type as field name and status.

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.

Implementors§

Source§

impl ThinContext for AssertionError

Source§

const VALUE: Self = AssertionError

Source§

impl ThinContext for AuthError

Source§

const VALUE: Self = AuthError

Source§

impl ThinContext for BuildError

Source§

const VALUE: Self = BuildError

Source§

impl ThinContext for ConfigError

Source§

const VALUE: Self = ConfigError

Source§

impl ThinContext for ConversionError

Source§

const VALUE: Self = ConversionError

Source§

impl ThinContext for DbError

Source§

const VALUE: Self = DbError

Source§

impl ThinContext for DecodeError

Source§

const VALUE: Self = DecodeError

Source§

impl ThinContext for EncodeError

Source§

const VALUE: Self = EncodeError

Source§

impl ThinContext for FsError

Source§

const VALUE: Self = FsError

Source§

impl ThinContext for InvalidInput

Source§

const VALUE: Self = InvalidInput

Source§

impl ThinContext for InvalidState

Source§

const VALUE: Self = InvalidState

Source§

impl ThinContext for InvalidStatus

Source§

const VALUE: Self = InvalidStatus

Source§

impl ThinContext for NetworkError

Source§

const VALUE: Self = NetworkError

Source§

impl ThinContext for NotFound

Source§

const VALUE: Self = NotFound

Source§

impl ThinContext for ParseError

Source§

const VALUE: Self = ParseError

Source§

impl ThinContext for SetupError

Source§

const VALUE: Self = SetupError