Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> one must define a new error enum that exists only to wrap the values returned by two different fallible functions belonging to different libraries

Saying this must be done is awfully strong here. There are other tools at your disposal, like dyn Error and the anyhow crate.



It "must" be done in the sense that `dyn Error`, anyhow, and (if we include zig's equivalent) inferred error sets mean something different than setting up an error enum. Using an error enum makes the failures explicit, which (most) other options choose to discard because they're designed to handle any error.

Your options effectively become either writing that enum, or using a macro that reduces to that enum. Unless, of course, you're willing to have the function signature say "eh, this function just breaks sometimes. Could be anything really."




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: