Seriously #rust #rustlang #rustdev #rustprogramming people:
Use `thiserror` in library crates! Only use `anyhow` in binary crates!
Don't give your users a hard time fighting against `anhyow::Error` when using your library!
Seriously #rust #rustlang #rustdev #rustprogramming people:
Use `thiserror` in library crates! Only use `anyhow` in binary crates!
Don't give your users a hard time fighting against `anhyow::Error` when using your library!
@musicmatze I'm pretty new to #rustlang and I haven't had the chance to use any of them.
Just in case, why is one encouraged over the other in some cases, and the other way around?
For me not to commit an error in the future, thanks! 😉
@sancas Nice that you ask! ❤️
There are two cases: Library crates and "Binary crates" (essentially: Applications).
In the case of an application, you _most of the time_ do no longer care about your error types. There has been an error while doing something? Nothing you can do about it, just show it to the user, log it, etc and carry on (or exit the application).
@musicmatze oh, I think I get the point.
With `anyhow` you get a generic Error type which may be convenient and easy way within your own app (in an scenario like something either worked or not).
But with `thiserror` you get different types of errors (network, timeout, out of bounds...) which can help you understand what's happening inside the library and decide next actions on top of it.
I get it now, thanks! 🙌
🚀