pub fn context_accumulator<E, I, C>(
contexts: I,
) -> impl Fn(E) -> ComposableError<E>Expand description
Creates a reusable closure that wraps errors with multiple contexts.
Returns a function that can be used with map_err to attach the same
set of contexts to multiple error paths.
§Arguments
contexts- Iterator of contexts to attach (must beClone)
§Examples
use error_rail::{context_accumulator, ErrorContext};
let contexts = vec![ErrorContext::tag("auth"), ErrorContext::tag("api")];
let add_contexts = context_accumulator(contexts);
let err = add_contexts("unauthorized");
assert_eq!(err.context().len(), 2);