1 unstable release
Uses new Rust 2024
new 0.1.0 | Apr 7, 2025 |
---|
#2 in #clonable
8KB
138 lines
Usage
You can also use the Untyped
variant of GenericError
if that suits your needs better.
There are also extension traits for convenience:
Also, for types that don't implement Debug
,
there are methods to suit your needs, e.g. GenericError::from_non_err
.
Only exports extension traits without polluting your namespace
Generic Error
A simple utility to convert any error type that isn't clonable into one that is,
while preserving source information providing Serialize
and Deserialize
functionality.
Magic?
How it works
The GenericError<E>
wrapper type just stores the Display
and Debug
implementations of the wrapped type,
which is now always clonable and will serialize just fine.
The GenericError<E>
type kinda looks like this:
#[derive(Serialize, Deserialize, Clone)]
pub struct GenericError<T>
{
display: String,
debug: String,
source: Option<GenericError>,
}
.. although many details have been omitted for brevity
Dependencies
~2MB
~44K SLoC