BoxedResultExt

Trait BoxedResultExt 

Source
pub trait BoxedResultExt<T, E> {
    // Required methods
    fn ctx_boxed<C: IntoErrorContext>(self, msg: C) -> Self;
    fn ctx_boxed_with<F>(self, f: F) -> Self
       where F: FnOnce() -> String;
}
Expand description

Extension trait for adding context to already-boxed ComposableError results.

This trait provides methods for enriching errors that are already wrapped in Box<ComposableError<E>>, allowing additional context to be added without re-boxing the error.

§Examples

use error_rail::{BoxedResultExt, ResultExt, ErrorContext};

fn inner_operation() -> Result<i32, Box<error_rail::ComposableError<&'static str>>> {
    Err("inner error").ctx("inner context")
}

fn outer_operation() -> Result<i32, Box<error_rail::ComposableError<&'static str>>> {
    inner_operation().ctx_boxed("outer context")
}

Required Methods§

Source

fn ctx_boxed<C: IntoErrorContext>(self, msg: C) -> Self

Adds additional context to an already-boxed ComposableError.

This method is useful when you have a Result<T, Box<ComposableError<E>>> and want to add more context without changing the error type.

§Arguments
  • msg - The context message to add, which must implement IntoErrorContext
§Examples
use error_rail::{BoxedResultExt, ResultExt};

let result: Result<i32, _> = Err("error").ctx("first context");
let enriched = result.ctx_boxed("second context");
Source

fn ctx_boxed_with<F>(self, f: F) -> Self
where F: FnOnce() -> String,

Adds lazily-evaluated context to an already-boxed ComposableError.

The context message is only computed if the result is an error, which can improve performance when context generation is expensive.

§Arguments
  • f - A closure that produces the context message
§Examples
use error_rail::{BoxedResultExt, ResultExt};

let result: Result<i32, _> = Err("error").ctx("first context");
let enriched = result.ctx_boxed_with(|| format!("context at {}", "runtime"));

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.

Implementations on Foreign Types§

Source§

impl<T, E> BoxedResultExt<T, E> for Result<T, Box<ComposableError<E>>>

Source§

fn ctx_boxed<C: IntoErrorContext>(self, msg: C) -> Self

Source§

fn ctx_boxed_with<F>(self, f: F) -> Self
where F: FnOnce() -> String,

Implementors§