#generic #clonable #clone #generic-err

generic-err

A small utility library to make errors always serializable and clonable

1 unstable release

Uses new Rust 2024

new 0.1.0 Apr 7, 2025

#2 in #clonable

GPL-2.0 license

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

See docs or the examples dir for usage

Dependencies

~2MB
~44K SLoC