5 ms·
But ? only worked if the function it was used in had the same error type as the function you called, which was mostly not the case... ... I think. I don't reme
by arghwhat 9y ago
But ? only worked if the function it was used in had the same error type as the function you called, which was mostly not the case...
... I think. I don't remember it that vividly.
- foldr 9y agoIt doesn't have to be the same type, there just has to be a suitable implementation of the 'From' trait to perform the conversion if the types don't match.
- steveklabnik 9y ago? calls a conversion function. It only won't work if the error you're trying to return won't convert to the error that's in the type signature. Even then, you have options, like .map_err.
- arghwhat 9y agoWe have gone a bit down a tangent here. My original complaint was about the friction of different error types compared to other languages (like, say, Go). Having to implement a bunch of From traits (unless you need io::Error, because everything seemed to have conversions from/to that), or having to implement inline error conversion through map_err, is such friction. I might go as far as consider it the most cumbersome error system I have used. Clean idea, cumbersome implementation. My comment about '?' not working with mismatched types was mostly just to say that it doesn't fix anything, it just adds a bit of convenient syntactic sugar.
- xfer 9y agoThere is zero friction if you use either error_chain/failure crate and you can still recover the precise underlying errors. The only thing is it allocates.
- red75prime 9y agofailure has no_std feature for the no-heap cases.
- arghwhat 9y agoI will look into those crates next time!