Carrier trait for ?
operator · Issue #1718 · rust-lang/rfcs (original) (raw)
We accepted an RFC to add the ?
operator, that RFC included a Carrier
trait to allow applying ?
to types other than Result
, e.g., Option
. However, we accepted a version of the RFC without that in order to get some actual movement and some experience with the ?
operator.
The bare ?
operator is now on the road to stabilisation. We would like to consider adding a Carrier
trait and that will require a new RFC. There is in fact a 'dummy' Carrier trait in libcore and used in the implementation of ?
. However, its purpose is to ensure ?
is backwards compatible around type inference. It is effectively only implemented for Result
and is not intended to be a long-term solution. There are other options for the trait using HKT, variant types, and just existing features. It's unclear what is preferred right now.
One important question is whether we should allow conversion between types (e.g., Result
to Option
) or whether we should only allow the ?
operator to work on one type 'at a time'.
Links: