If you're making a library, don't use the
failure crate. Instead:
- define an
enumthat covers meaningful error cases for your library,
std::error::Errorfor that enum.
And that's it. This is going to be fast/cheap (no heap allocation on error), and precise and easy to use (instead of an opaque object, stringly-typed errors, or a nested
Kind type, you get exact cases right there).
It won't have extra features, like backtraces or contexts, but I'm going to argue that for a library these are unnecessary, and just leak implementation details.
Thanks to the
std::error::Error implementation, writers of applications will be able to seamlessly wrap/convert such errors to
Failure or other types.