Not entirely sure why I’m specifically being summoned, here… but alright.
My concern with this is that if a function accepts a
Result, the last thing I would expect is for it to just unwrap it, especially if it also returns a
Result. I mean, ideally you shouldn’t be calling
unwrap at all, especially not in a library.
Aside: I feel like “thou shalt not panic in thine libraries” should be written in huge, fifty foot high burning letters on the side of a mountain somewhere. There is nothing more frustrating than having a failure in a component that you just can’t practically isolate.
I appreciate that Rust error handling can get really verbose, but I think that should be taken as motivation to provide simpler constructs in the language. I think this is one of those cases where the language absolutely needs to be convenient; if correct error handling is too hard, people start coming up with wacky work-arounds.
Also, why not go the other way around? Have the trait convert into a
try! that as the first step in the function? The error propagation is still there, even if it’s a lot less efficient.
sigh I really, really wish we had suffix
?. Or even just method macros!
Anyway, summary since I only just woke up and may have rambled a bit: I don’t recommend doing this; it’s subverting reasonable expectations and making your interface look less panicky than it arguably is. If there’s a pain point, that should be use to motivate change in the language.