@@ -2918,15 +2918,9 @@ pub trait BoxPlace<Data: ?Sized> : Place<Data> {
29182918 fn make_place ( ) -> Self ;
29192919}
29202920
2921- /// A trait for types which have success and error states and are meant to work
2922- /// with the question mark operator.
2923- /// When the `?` operator is used with a value, whether the value is in the
2924- /// success or error state is determined by calling `translate`.
2925- ///
2926- /// This trait is **very** experimental, it will probably be iterated on heavily
2927- /// before it is stabilised. Implementors should expect change. Users of `?`
2928- /// should not rely on any implementations of `Carrier` other than `Result`,
2929- /// i.e., you should not expect `?` to continue to work with `Option`, etc.
2921+ /// This trait has been superseded by the `Try` trait, but must remain
2922+ /// here as `?` is still lowered to it in stage0 .
2923+ #[ cfg( stage0) ]
29302924#[ unstable( feature = "question_mark_carrier" , issue = "31436" ) ]
29312925pub trait Carrier {
29322926 /// The type of the value when computation succeeds.
@@ -2945,6 +2939,7 @@ pub trait Carrier {
29452939 fn translate < T > ( self ) -> T where T : Carrier < Success =Self :: Success , Error =Self :: Error > ;
29462940}
29472941
2942+ #[ cfg( stage0) ]
29482943#[ unstable( feature = "question_mark_carrier" , issue = "31436" ) ]
29492944impl < U , V > Carrier for Result < U , V > {
29502945 type Success = U ;
@@ -2970,21 +2965,57 @@ impl<U, V> Carrier for Result<U, V> {
29702965
29712966struct _DummyErrorType ;
29722967
2973- impl Carrier for _DummyErrorType {
2974- type Success = ( ) ;
2968+ impl Try for _DummyErrorType {
2969+ type Ok = ( ) ;
29752970 type Error = ( ) ;
29762971
2977- fn from_success ( _: ( ) ) -> _DummyErrorType {
2972+ fn into_result ( self ) -> Result < Self :: Ok , Self :: Error > {
2973+ Ok ( ( ) )
2974+ }
2975+
2976+ fn from_ok ( _: ( ) ) -> _DummyErrorType {
29782977 _DummyErrorType
29792978 }
29802979
29812980 fn from_error ( _: ( ) ) -> _DummyErrorType {
29822981 _DummyErrorType
29832982 }
2983+ }
29842984
2985- fn translate < T > ( self ) -> T
2986- where T : Carrier < Success =( ) , Error =( ) >
2987- {
2988- T :: from_success ( ( ) )
2989- }
2985+ /// A trait for customizing the behaviour of the `?` operator.
2986+ ///
2987+ /// A type implementing `Try` is one that has a canonical way to view it
2988+ /// in terms of a success/failure dichotomy. This trait allows both
2989+ /// extracting those success or failure values from an existing instance and
2990+ /// creating a new instance from a success or failure value.
2991+ #[ unstable( feature = "try_trait" , issue = "42327" ) ]
2992+ pub trait Try {
2993+ /// The type of this value when viewed as successful.
2994+ #[ unstable( feature = "try_trait" , issue = "42327" ) ]
2995+ type Ok ;
2996+ /// The type of this value when viewed as failed.
2997+ #[ unstable( feature = "try_trait" , issue = "42327" ) ]
2998+ type Error ;
2999+
3000+ /// Applies the "?" operator. A return of `Ok(t)` means that the
3001+ /// execution should continue normally, and the result of `?` is the
3002+ /// value `t`. A return of `Err(e)` means that execution should branch
3003+ /// to the innermost enclosing `catch`, or return from the function.
3004+ ///
3005+ /// If an `Err(e)` result is returned, the value `e` will be "wrapped"
3006+ /// in the return type of the enclosing scope (which must itself implement
3007+ /// `Try`). Specifically, the value `X::from_error(From::from(e))`
3008+ /// is returned, where `X` is the return type of the enclosing function.
3009+ #[ unstable( feature = "try_trait" , issue = "42327" ) ]
3010+ fn into_result ( self ) -> Result < Self :: Ok , Self :: Error > ;
3011+
3012+ /// Wrap an error value to construct the composite result. For example,
3013+ /// `Result::Err(x)` and `Result::from_error(x)` are equivalent.
3014+ #[ unstable( feature = "try_trait" , issue = "42327" ) ]
3015+ fn from_error ( v : Self :: Error ) -> Self ;
3016+
3017+ /// Wrap an OK value to construct the composite result. For example,
3018+ /// `Result::Ok(x)` and `Result::from_ok(x)` are equivalent.
3019+ #[ unstable( feature = "try_trait" , issue = "42327" ) ]
3020+ fn from_ok ( v : Self :: Ok ) -> Self ;
29903021}
0 commit comments