@@ -152,6 +152,7 @@ mod bit;
152
152
mod function;
153
153
mod place;
154
154
mod range;
155
+ mod try;
155
156
156
157
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
157
158
pub use self :: arith:: { Add , Sub , Mul , Div , Rem , Neg } ;
@@ -172,6 +173,12 @@ pub use self::range::{Range, RangeFrom, RangeFull, RangeTo};
172
173
#[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
173
174
pub use self :: range:: { RangeInclusive , RangeToInclusive } ;
174
175
176
+ #[ unstable( feature = "question_mark_carrier" , issue = "31436" ) ]
177
+ #[ cfg( stage0) ]
178
+ pub use self :: try:: Carrier ;
179
+ #[ unstable( feature = "try_trait" , issue = "42327" ) ]
180
+ pub use self :: try:: Try ;
181
+
175
182
#[ unstable( feature = "placement_new_protocol" , issue = "27779" ) ]
176
183
pub use self :: place:: { Place , Placer , InPlace , Boxed , BoxPlace } ;
177
184
@@ -593,105 +600,3 @@ impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {}
593
600
// *const T -> *const U
594
601
#[ unstable( feature = "coerce_unsized" , issue = "27732" ) ]
595
602
impl < T : ?Sized +Unsize < U > , U : ?Sized > CoerceUnsized < * const U > for * const T { }
596
-
597
- /// This trait has been superseded by the `Try` trait, but must remain
598
- /// here as `?` is still lowered to it in stage0 .
599
- #[ cfg( stage0) ]
600
- #[ unstable( feature = "question_mark_carrier" , issue = "31436" ) ]
601
- pub trait Carrier {
602
- /// The type of the value when computation succeeds.
603
- type Success ;
604
- /// The type of the value when computation errors out.
605
- type Error ;
606
-
607
- /// Create a `Carrier` from a success value.
608
- fn from_success ( _: Self :: Success ) -> Self ;
609
-
610
- /// Create a `Carrier` from an error value.
611
- fn from_error ( _: Self :: Error ) -> Self ;
612
-
613
- /// Translate this `Carrier` to another implementation of `Carrier` with the
614
- /// same associated types.
615
- fn translate < T > ( self ) -> T where T : Carrier < Success =Self :: Success , Error =Self :: Error > ;
616
- }
617
-
618
- #[ cfg( stage0) ]
619
- #[ unstable( feature = "question_mark_carrier" , issue = "31436" ) ]
620
- impl < U , V > Carrier for Result < U , V > {
621
- type Success = U ;
622
- type Error = V ;
623
-
624
- fn from_success ( u : U ) -> Result < U , V > {
625
- Ok ( u)
626
- }
627
-
628
- fn from_error ( e : V ) -> Result < U , V > {
629
- Err ( e)
630
- }
631
-
632
- fn translate < T > ( self ) -> T
633
- where T : Carrier < Success =U , Error =V >
634
- {
635
- match self {
636
- Ok ( u) => T :: from_success ( u) ,
637
- Err ( e) => T :: from_error ( e) ,
638
- }
639
- }
640
- }
641
-
642
- struct _DummyErrorType ;
643
-
644
- impl Try for _DummyErrorType {
645
- type Ok = ( ) ;
646
- type Error = ( ) ;
647
-
648
- fn into_result ( self ) -> Result < Self :: Ok , Self :: Error > {
649
- Ok ( ( ) )
650
- }
651
-
652
- fn from_ok ( _: ( ) ) -> _DummyErrorType {
653
- _DummyErrorType
654
- }
655
-
656
- fn from_error ( _: ( ) ) -> _DummyErrorType {
657
- _DummyErrorType
658
- }
659
- }
660
-
661
- /// A trait for customizing the behaviour of the `?` operator.
662
- ///
663
- /// A type implementing `Try` is one that has a canonical way to view it
664
- /// in terms of a success/failure dichotomy. This trait allows both
665
- /// extracting those success or failure values from an existing instance and
666
- /// creating a new instance from a success or failure value.
667
- #[ unstable( feature = "try_trait" , issue = "42327" ) ]
668
- pub trait Try {
669
- /// The type of this value when viewed as successful.
670
- #[ unstable( feature = "try_trait" , issue = "42327" ) ]
671
- type Ok ;
672
- /// The type of this value when viewed as failed.
673
- #[ unstable( feature = "try_trait" , issue = "42327" ) ]
674
- type Error ;
675
-
676
- /// Applies the "?" operator. A return of `Ok(t)` means that the
677
- /// execution should continue normally, and the result of `?` is the
678
- /// value `t`. A return of `Err(e)` means that execution should branch
679
- /// to the innermost enclosing `catch`, or return from the function.
680
- ///
681
- /// If an `Err(e)` result is returned, the value `e` will be "wrapped"
682
- /// in the return type of the enclosing scope (which must itself implement
683
- /// `Try`). Specifically, the value `X::from_error(From::from(e))`
684
- /// is returned, where `X` is the return type of the enclosing function.
685
- #[ unstable( feature = "try_trait" , issue = "42327" ) ]
686
- fn into_result ( self ) -> Result < Self :: Ok , Self :: Error > ;
687
-
688
- /// Wrap an error value to construct the composite result. For example,
689
- /// `Result::Err(x)` and `Result::from_error(x)` are equivalent.
690
- #[ unstable( feature = "try_trait" , issue = "42327" ) ]
691
- fn from_error ( v : Self :: Error ) -> Self ;
692
-
693
- /// Wrap an OK value to construct the composite result. For example,
694
- /// `Result::Ok(x)` and `Result::from_ok(x)` are equivalent.
695
- #[ unstable( feature = "try_trait" , issue = "42327" ) ]
696
- fn from_ok ( v : Self :: Ok ) -> Self ;
697
- }
0 commit comments