On Error Handling in Rust
felix-knorr.net·18w·
Flag this post

The current standard for error handling, when writing a crate, is to define one error enum per module, or one for the whole crate that covers all error cases that the module or crate can possibly produce, and each public function that returns a Result will use said error enum.

This means, that a function will return an error enum, containing error variants that the function cannot even produce. If you match on this error enum, you will have to manually distinguish which of those variants are not applicable in your current scope, based on the documentation of the function (and who reads that anyway? /s).

The problem with the status quo

What makes Rust so great, is the ability to express requirements via the type system in a way that makes it very hard for you to violate them, a…

Similar Posts

Loading similar posts...