Managing errors

If you have used multiple libraries in Rust, you will probably have noticed that managing errors is not straightforward. We have the awesome ? operator, but if a function has multiple errors, it's not so easy to use. We can create our own error types, have variants for each of them, and have an Into trait implementation for each of the errors we might encounter. This is a tedious approach, but until recently it was the only way.

Luckily, we have a crate that can help us with that. This crate provides us with a Fail trait, which already guarantees thread safety and already provides default conversion implementations from all standard library error types. It also gives us some macros that help us with some boilerplate code. ...

Get Rust High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.