Skip to main content

context_accumulator

Function context_accumulator 

Source
pub fn context_accumulator<E, I, C>(
    contexts: I,
) -> impl Fn(E) -> ComposableError<E>
where I: IntoIterator<Item = C> + Clone, C: IntoErrorContext + Clone,
Expand description

Creates a context accumulator function.

This returns a function that can accumulate multiple contexts onto an error. The returned function can be reused for multiple errors with the same context pattern.

§Type Parameters

  • I: The iterator type for contexts
  • C: The context item type

§Arguments

  • contexts: The contexts to accumulate

§Examples

use rustica::error::context_accumulator;

let contexts = vec!["database error", "user operation failed"];
let accumulator = context_accumulator(contexts);

let error1 = "connection timeout";
let error2 = "query failed";

let contextual1 = accumulator(error1);
let contextual2 = accumulator(error2);

// Both errors now have the same context stack
assert_eq!(contextual1.context().len(), 2);
assert_eq!(contextual2.context().len(), 2);