Crate flex_error[−][src]
Expand description
flex-error
is a lightweight Rust library that uses macros and traits
to switch between different error tracing implementations and no_std. The library currently supports 3 modes via Cargo feature flags: eyre_tracer
(default), anyhow_tracer
, and string_tracer
(no_std).
The library separates out several concepts as traits:
ErrorDetail
, ErrorTracer
, and ErrorSource
.
-
ErrorDetail
is responsible to structured metadata information about a specific error. -
ErrorTracer
is responsible for tracing error chains and backtraces. -
ErrorSource
allows generic conversion of external error types into an ErrorDetail with optional ErrorTrace. -
An application error is of type
ErrorReport<ErrorDetail, ErrorTracer>
, which holds both the error details and trace.
With the separation of concerns, flex-error
allows applications to easily
switch between different error reporting implementations,
such as eyre
and anyhow
, by implementing
ErrorTracer
for the respective reporters.
flex-error
defines a define_error!
macro that define custom Detail
types and error types as alias to
ErrorReport<Detail, DefaultTracer>
.
The DefaultTracer
type is set globally by the feature flag, so that
application error types do not have to be over-generalized.
The trade off is that it is not possible to use multiple
ErrorTracer
implementations at the same time across different crates that
use flex-error
.
Modules
macros | |
tracer_impl |
Macros
define_error |
|
define_error_with_tracer | This macro allows error types to be defined with custom error tracer types
other than |
Structs
DetailOnly | An |
DisplayError | An |
ErrorReport | An |
NoSource | An |
StdError | An |
TraceOnly | An |
Traits
ErrorMessageTracer | An |
ErrorSource | A type implementing |
ErrorTracer | An error tracer implements |
Type Definitions
AsErrorDetail | Type alias to |
AsErrorSource | Type alias to |
DefaultTracer | The |