@@ -981,42 +981,75 @@ impl<T: Default, E> Result<T, E> {
981
981
982
982
#[ unstable( feature = "inner_deref" , reason = "newly added" , issue = "50264" ) ]
983
983
impl < T : Deref , E > Result < T , E > {
984
- /// Converts from `&Result<T, E>` to `Result<&T::Target, &E>`.
984
+ /// Converts from `Result<T, E>` (or ` &Result<T, E>`) to `Result<&T::Target, &E>`.
985
985
///
986
- /// Leaves the original Result in-place, creating a new one with a reference
987
- /// to the original one, additionally coercing the `Ok` arm of the Result via
988
- /// `Deref`.
989
- pub fn deref_ok ( & self ) -> Result < & T :: Target , & E > {
986
+ /// Leaves the original `Result` in-place, creating a new one containing a reference to the
987
+ /// `Ok` type's `Deref::Target` type.
988
+ pub fn as_deref_ok ( & self ) -> Result < & T :: Target , & E > {
990
989
self . as_ref ( ) . map ( |t| t. deref ( ) )
991
990
}
992
991
}
993
992
994
993
#[ unstable( feature = "inner_deref" , reason = "newly added" , issue = "50264" ) ]
995
994
impl < T , E : Deref > Result < T , E > {
996
- /// Converts from `&Result<T, E>` to `Result<&T, &E::Target>`.
995
+ /// Converts from `Result<T, E>` (or ` &Result<T, E>`) to `Result<&T, &E::Target>`.
997
996
///
998
- /// Leaves the original Result in-place, creating a new one with a reference
999
- /// to the original one, additionally coercing the `Err` arm of the Result via
1000
- /// `Deref`.
1001
- pub fn deref_err ( & self ) -> Result < & T , & E :: Target >
997
+ /// Leaves the original `Result` in-place, creating a new one containing a reference to the
998
+ /// `Err` type's `Deref::Target` type.
999
+ pub fn as_deref_err ( & self ) -> Result < & T , & E :: Target >
1002
1000
{
1003
1001
self . as_ref ( ) . map_err ( |e| e. deref ( ) )
1004
1002
}
1005
1003
}
1006
1004
1007
1005
#[ unstable( feature = "inner_deref" , reason = "newly added" , issue = "50264" ) ]
1008
1006
impl < T : Deref , E : Deref > Result < T , E > {
1009
- /// Converts from `&Result<T, E>` to `Result<&T::Target, &E::Target>`.
1007
+ /// Converts from `Result<T, E>` (or ` &Result<T, E>`) to `Result<&T::Target, &E::Target>`.
1010
1008
///
1011
- /// Leaves the original Result in-place, creating a new one with a reference
1012
- /// to the original one, additionally coercing both the `Ok` and `Err` arms
1013
- /// of the Result via `Deref`.
1014
- pub fn deref ( & self ) -> Result < & T :: Target , & E :: Target >
1009
+ /// Leaves the original `Result` in-place, creating a new one containing a reference to both
1010
+ /// the `Ok` and `Err` types' `Deref::Target` types.
1011
+ pub fn as_deref ( & self ) -> Result < & T :: Target , & E :: Target >
1015
1012
{
1016
1013
self . as_ref ( ) . map ( |t| t. deref ( ) ) . map_err ( |e| e. deref ( ) )
1017
1014
}
1018
1015
}
1019
1016
1017
+ #[ unstable( feature = "inner_deref" , reason = "newly added" , issue = "50264" ) ]
1018
+ impl < T : DerefMut , E > Result < T , E > {
1019
+ /// Converts from `Result<T, E>` (or `&mut Result<T, E>`) to `Result<&mut T::Target, &mut E>`.
1020
+ ///
1021
+ /// Leaves the original `Result` in-place, creating a new one containing a mutable reference to
1022
+ /// the `Ok` type's `Deref::Target` type.
1023
+ pub fn as_deref_mut_ok ( & mut self ) -> Result < & mut T :: Target , & mut E > {
1024
+ self . as_mut ( ) . map ( |t| t. deref_mut ( ) )
1025
+ }
1026
+ }
1027
+
1028
+ #[ unstable( feature = "inner_deref" , reason = "newly added" , issue = "50264" ) ]
1029
+ impl < T , E : DerefMut > Result < T , E > {
1030
+ /// Converts from `Result<T, E>` (or `&mut Result<T, E>`) to `Result<&mut T, &mut E::Target>`.
1031
+ ///
1032
+ /// Leaves the original `Result` in-place, creating a new one containing a mutable reference to
1033
+ /// the `Err` type's `Deref::Target` type.
1034
+ pub fn as_deref_mut_err ( & mut self ) -> Result < & mut T , & mut E :: Target >
1035
+ {
1036
+ self . as_mut ( ) . map_err ( |e| e. deref_mut ( ) )
1037
+ }
1038
+ }
1039
+
1040
+ #[ unstable( feature = "inner_deref" , reason = "newly added" , issue = "50264" ) ]
1041
+ impl < T : DerefMut , E : DerefMut > Result < T , E > {
1042
+ /// Converts from `Result<T, E>` (or `&mut Result<T, E>`) to
1043
+ /// `Result<&mut T::Target, &mut E::Target>`.
1044
+ ///
1045
+ /// Leaves the original `Result` in-place, creating a new one containing a mutable reference to
1046
+ /// both the `Ok` and `Err` types' `Deref::Target` types.
1047
+ pub fn as_deref_mut ( & mut self ) -> Result < & mut T :: Target , & mut E :: Target >
1048
+ {
1049
+ self . as_mut ( ) . map ( |t| t. deref_mut ( ) ) . map_err ( |e| e. deref_mut ( ) )
1050
+ }
1051
+ }
1052
+
1020
1053
impl < T , E > Result < Option < T > , E > {
1021
1054
/// Transposes a `Result` of an `Option` into an `Option` of a `Result`.
1022
1055
///
0 commit comments