Improving your error handling in Rust
This is another blog in my fledgling series on Rust as I learn the language. In this blog I touch on a few cool crates that can improve your error handling in Rust. It follows nicely from my prior post on logging in Rust. As with that post, this is just an introductory look at error handling. There is a lot more one can learn about error handling (in Rust or otherwise) than I will cover here. Here I will just touch on a few crates that can get you started. Maybe in future posts I will get into more detail on other topics, but there are also good blogs out there already (e.g. this).
As a newbie, please feel free in the comments to elaborate on what I might be doing wrong, could do better or is not “canonical” Rust.
So let’s dive in.
To be specific, in this blog I will cover defining and using error types specific to your project (application/library). I will also mention a cool crate to make your panic output look a bit better to facilitate debugging, and in doing so touch on Rust’s ‘feature’ mechanism and how you can create and use your own features, in this case to enable/disable the panic output pretification.
std::result::Result<T, E>
Error handling starts with a Result<T, E>
. I will assume you know the difference between an Option
and a Result
, and in your…