On 2016-12-20 8:46 AM, Jan de Mooij wrote:
> Hi all,
> 
> A few weeks ago we added mozilla::Result<V, E> to MFBT [0][1].

Amazing!

> I was asked
> to inform dev-platform about this, so here's a quick overview.
> mozilla::Result<V, E> is based on Rust's Result type [2]. It contains
> either a success value of type V or an error value of type E. For example,
> a function Foo that returns an `int` on success or some `Error` (enum,
> pointer, etc) on failure, would have this signature:
> 
>   Result<int, Error> Foo();
> 
> mozilla::Ok is an empty struct that can be used when a function doesn't
> return anything on success:
> 
>   Result<Ok, Error> Bar() { ... return Ok(); }
> 
> The MOZ_TRY(expr) macro is similar to Rust's try! macro: if `expr` is an
> error it propagates it to the caller, else it continues:
> 
>   Result<V, E> Baz() { MOZ_TRY(Bar()); ... }

I have one question: what is Bar() expected to return here?  An E type,
or a type that's implicitly convertible to E
(<https://searchfox.org/mozilla-central/rev/cc2a84852bd4e6f6d8d4d5b17b8382bb5d005749/mfbt/Result.h#198>
suggests that this is the case), or something else?  Is there a
potential for mistakes like for example caused by the error types being
implicitly convertible to each other but the values changing their
meanings upon the conversion (for example a bool error type getting
converted to an int error type)?
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to