On Wed, Dec 21, 2016, at 12:30 PM, Jason Orendorff wrote:
> The implicit conversion solves a real problem. Imagine these two
> operations
> have two different error types:
> 
>         MOZ_TRY(JS_DoFirstThing()); // JS::Error&
>         MOZ_TRY(mozilla::pkix::DoSecondThing()); // pkix::Error
> 
> We don't want our error-handling scheme getting in the way of using them
> together. So we need a way of unifying the two error types: a shared base
> class, perhaps, or a variant.
> 
> Experience with Rust says that MOZ_TRY definitely needs to address this
> problem somehow. C++ implicit conversion is just one way to go; we can
> discuss alternatives in the bug.

The `try` macro in Rust will auto-convert error types that implement
`Into<E>`, AIUI, but that's not automatic for all error types. I haven't
tried it, but I have seen multiple recommendations for the `error_chain`
crate to make this smoother:
https://docs.rs/error-chain/0.7.1/error_chain/

It's basically just boilerplate to implement conversions from other
error types. I wouldn't be surprised if something like that percolates
into the Rust standard library at some point.

-Ted
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to