Tracing Result
A library for ergonomic error handling with tracing support.
This crate provides a wrapper around Result, Option & any other types
which implement Try that automatically emits tracing messages at configurable log levels
when unpacked via the ? operator.
Overview
The Trace trait extends all Try-types T with methods that wrap it in a Traced<T>
with a custom tracing message. The message is emitted automatically when the Traced<T> is
used with the ? operator.
Simply use tracing_result::Trace to bring the methods into scope. The blanket implementation
ensures availability on all Try-types, not only Result& Option.
There are two families of methods:
or_*methods (or_error,or_warn,or_info,or_debug,or_trace): Log the message when anErr/Noneetc. is unpackedand_*methods (and_error,and_warn,and_info,and_debug,and_trace): Log the message when anOk/Someetc. is unpacked
Examples
Traced<Result>
use io;
use Trace;
Traced<Option>
use Trace;
use ;
let data: = Vecnew;
let first_value = data
.first
.or_warn // Emitted if `None`
.and_then // `Transform` methods call `Try::branch` and therefore emit
.or_warn // Emitted if `None`
.unwrap_or_default; // `Extract` methods call `Try::branch` and therefore emit
assert_eq!;