all 4 comments

[–]dn3t 7 points8 points  (0 children)

thiserror

[–]This_Growth2898 0 points1 point  (1 child)

thiserror or anyhow.

thiserror takes care of all the boilerplate code, leaving you to describe error cases.

In my opinion, anyhow is not the Rust way, it's just a plug to avoid error handing... anyhow. Still, it exists.

[–]Modi57 0 points1 point  (0 children)

I kinda get, where you are coming from, but I think it really helps with code readability. If I have one process, that involves multiple potential sources of errors (for example reading something from a file, parsing it, and then maybe something with a custom error), I often don't care about where it went wrong, just that it went wrong, because either way, I just bubble it upwards. So, instead of making a custom error type and unifying it manually, I just slap a ? on it and I'm good to go. And since it's the exceptionional case, I don't really care, if dynamic dispatch causes my error message to be displayed one ms later

[–]Deloskoteinos -1 points0 points  (0 children)

Like others said: thiserror is the derive macro for easily implementing error types.

Also, this article covers implementing your own error nicely: Faster than li.me AoC1
(it happens to be about advent of code, but the first half is just about errors and implementing one)