@@ -981,42 +981,75 @@ impl<T: Default, E> Result<T, E> {
981981
982982#[ unstable( feature = "inner_deref" , reason = "newly added" , issue = "50264" ) ]
983983impl < 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>`.
985985 ///
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 > {
990989 self . as_ref ( ) . map ( |t| t. deref ( ) )
991990 }
992991}
993992
994993#[ unstable( feature = "inner_deref" , reason = "newly added" , issue = "50264" ) ]
995994impl < 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>`.
997996 ///
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 >
10021000 {
10031001 self . as_ref ( ) . map_err ( |e| e. deref ( ) )
10041002 }
10051003}
10061004
10071005#[ unstable( feature = "inner_deref" , reason = "newly added" , issue = "50264" ) ]
10081006impl < 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>`.
10101008 ///
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 >
10151012 {
10161013 self . as_ref ( ) . map ( |t| t. deref ( ) ) . map_err ( |e| e. deref ( ) )
10171014 }
10181015}
10191016
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+
10201053impl < T , E > Result < Option < T > , E > {
10211054 /// Transposes a `Result` of an `Option` into an `Option` of a `Result`.
10221055 ///
0 commit comments