Modular Errors in Rust
I encourage people to check out my SNAFU crate [1]. I urge users to create many distinct error types (usually enums but also structs) and compose them — so much so that I advocate that you never create each specific error in more than one source location. That means that the collection of error types produces a unique trace through your program, uniquely identifying the source of the error with no runtime cost (compare this to a runtime-collected stacktrace &#x2F; backtrace).<p>Here&#x27;s how the final example in the blog post would look like with a quick transform to SNAFU: <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;shepmaster&#x2F;fb7f4c9519a074ea7186ca7b75afb9dd" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;shepmaster&#x2F;fb7f4c9519a074ea7186ca7b7...</a>. If I spent more time, there&#x27;d probably be a bit more changes, but hopefully that gets the idea across.<p>[1]: <a href="https:&#x2F;&#x2F;docs.rs&#x2F;snafu&#x2F;" rel="nofollow">https:&#x2F;&#x2F;docs.rs&#x2F;snafu&#x2F;</a>