@@ -909,6 +909,40 @@ impl<T: Default, E> Result<T, E> {
909
909
}
910
910
}
911
911
912
+ impl < T : Deref , E : Deref > Result < T , E > {
913
+ #[ unstable( feature = "inner_deref" , reason = "newly added" , issue = "50264" ) ]
914
+ /// Converts from `&Result<T, E>` to `Result<&T::Target, &E>`.
915
+ ///
916
+ /// Leaves the original Result in-place, creating a new one with a reference
917
+ /// to the original one, additionally coercing the `Ok` arm of the Result via
918
+ /// `Deref`.
919
+ pub fn deref_ok ( & self ) -> Result < & T :: Target , & E > {
920
+ self . as_ref ( ) . map ( |t| t. deref ( ) )
921
+ }
922
+
923
+ #[ unstable( feature = "inner_deref" , reason = "newly added" , issue = "50264" ) ]
924
+ /// Converts from `&Result<T, E>` to `Result<&T, &E::Target>`.
925
+ ///
926
+ /// Leaves the original Result in-place, creating a new one with a reference
927
+ /// to the original one, additionally coercing the `Err` arm of the Result via
928
+ /// `Deref`.
929
+ pub fn deref_err ( & self ) -> Result < & T , & E :: Target >
930
+ {
931
+ self . as_ref ( ) . map_err ( |e| e. deref ( ) )
932
+ }
933
+
934
+ #[ unstable( feature = "inner_deref" , reason = "newly added" , issue = "50264" ) ]
935
+ /// Converts from `&Result<T, E>` to `Result<&T::Target, &E::Target>`.
936
+ ///
937
+ /// Leaves the original Result in-place, creating a new one with a reference
938
+ /// to the original one, additionally coercing both the `Ok` and `Err` arms
939
+ /// of the Result via `Deref`.
940
+ pub fn deref ( & self ) -> Result < & T :: Target , & E :: Target >
941
+ {
942
+ self . as_ref ( ) . map ( |t| t. deref ( ) ) . map_err ( |e| e. deref ( ) )
943
+ }
944
+ }
945
+
912
946
impl < T , E > Result < Option < T > , E > {
913
947
/// Transposes a `Result` of an `Option` into an `Option` of a `Result`.
914
948
///
@@ -999,63 +1033,6 @@ impl<'a, T, E> IntoIterator for &'a mut Result<T, E> {
999
1033
}
1000
1034
}
1001
1035
1002
- #[ unstable( feature = "inner_deref" , reason = "newly added" , issue = "50264" ) ]
1003
- /// Extension trait to get a reference to a Result via the Deref trait.
1004
- pub trait ResultDeref < T , E > {
1005
- /// Converts from `&Result<T, E>` to `Result<&T::Target, &E>`.
1006
- ///
1007
- /// Leaves the original Result in-place, creating a new one with a reference
1008
- /// to the original one, additionally coercing the `Ok` arm of the Result via
1009
- /// `Deref`.
1010
- fn deref_ok ( & self ) -> Result < & T :: Target , & E >
1011
- where
1012
- T : Deref ;
1013
-
1014
- /// Converts from `&Result<T, E>` to `Result<&T, &E::Target>`.
1015
- ///
1016
- /// Leaves the original Result in-place, creating a new one with a reference
1017
- /// to the original one, additionally coercing the `Err` arm of the Result via
1018
- /// `Deref`.
1019
- fn deref_err ( & self ) -> Result < & T , & E :: Target >
1020
- where
1021
- E : Deref ;
1022
-
1023
- /// Converts from `&Result<T, E>` to `Result<&T::Target, &E::Target>`.
1024
- ///
1025
- /// Leaves the original Result in-place, creating a new one with a reference
1026
- /// to the original one, additionally coercing both the `Ok` and `Err` arms
1027
- /// of the Result via `Deref`.
1028
- fn deref ( & self ) -> Result < & T :: Target , & E :: Target >
1029
- where
1030
- T : Deref ,
1031
- E : Deref ;
1032
- }
1033
-
1034
- #[ unstable( feature = "inner_deref" , reason = "newly added" , issue = "50264" ) ]
1035
- impl < T , E > ResultDeref < T , E > for Result < T , E > {
1036
- fn deref_ok ( & self ) -> Result < & T :: Target , & E >
1037
- where
1038
- T : Deref ,
1039
- {
1040
- self . as_ref ( ) . map ( |t| t. deref ( ) )
1041
- }
1042
-
1043
- fn deref_err ( & self ) -> Result < & T , & E :: Target >
1044
- where
1045
- E : Deref ,
1046
- {
1047
- self . as_ref ( ) . map_err ( |e| e. deref ( ) )
1048
- }
1049
-
1050
- fn deref ( & self ) -> Result < & T :: Target , & E :: Target >
1051
- where
1052
- T : Deref ,
1053
- E : Deref ,
1054
- {
1055
- self . as_ref ( ) . map ( |t| t. deref ( ) ) . map_err ( |e| e. deref ( ) )
1056
- }
1057
- }
1058
-
1059
1036
/////////////////////////////////////////////////////////////////////////////
1060
1037
// The Result Iterators
1061
1038
/////////////////////////////////////////////////////////////////////////////
0 commit comments