@@ -835,7 +835,7 @@ impl<T: Copy, E> Result<&T, E> {
835
835
/// assert_eq!(copied, Ok(12));
836
836
/// ```
837
837
#[ unstable( feature = "result_copied" , reason = "newly added" , issue = "63168" ) ]
838
- pub fn copied ( self ) -> Result < T , E > {
838
+ pub fn copied_ok ( self ) -> Result < T , E > {
839
839
self . map ( |& t| t)
840
840
}
841
841
}
@@ -855,7 +855,7 @@ impl<T: Copy, E> Result<&mut T, E> {
855
855
/// assert_eq!(copied, Ok(12));
856
856
/// ```
857
857
#[ unstable( feature = "result_copied" , reason = "newly added" , issue = "63168" ) ]
858
- pub fn copied ( self ) -> Result < T , E > {
858
+ pub fn copied_ok ( self ) -> Result < T , E > {
859
859
self . map ( |& mut t| t)
860
860
}
861
861
}
@@ -900,6 +900,74 @@ impl<T, E: Copy> Result<T, &mut E> {
900
900
}
901
901
}
902
902
903
+ impl < T : Copy , E : Copy > Result < & T , & E > {
904
+ /// Maps a `Result<&T, &E>` to a `Result<T, E>` by copying the
905
+ /// contents of the result.
906
+ ///
907
+ /// # Examples
908
+ ///
909
+ /// ```
910
+ /// #![feature(result_copied)]
911
+ /// assert_eq!(Err(&1), Err(1));
912
+ /// assert_eq!(Ok(&42), Ok(42));
913
+ /// ```
914
+ #[ unstable( feature = "result_copied" , reason = "newly added" , issue = "63168" ) ]
915
+ pub fn copied ( self ) -> Result < T , E > {
916
+ self . copied_ok ( ) . copied_err ( )
917
+ }
918
+ }
919
+
920
+ impl < T : Copy , E : Copy > Result < & mut T , & E > {
921
+ /// Maps a `Result<&mut T, &E>` to a `Result<T, E>` by copying the
922
+ /// contents of the result.
923
+ ///
924
+ /// # Examples
925
+ ///
926
+ /// ```
927
+ /// #![feature(result_copied)]
928
+ /// assert_eq!(Err(&1), Err(1));
929
+ /// assert_eq!(Ok(&mut 42), Ok(42));
930
+ /// ```
931
+ #[ unstable( feature = "result_copied" , reason = "newly added" , issue = "63168" ) ]
932
+ pub fn copied ( self ) -> Result < T , E > {
933
+ self . copied_ok ( ) . copied_err ( )
934
+ }
935
+ }
936
+
937
+ impl < T : Copy , E : Copy > Result < & T , & mut E > {
938
+ /// Maps a `Result<&T, &mut E>` to a `Result<T, E>` by copying the
939
+ /// contents of the result.
940
+ ///
941
+ /// # Examples
942
+ ///
943
+ /// ```
944
+ /// #![feature(result_copied)]
945
+ /// assert_eq!(Err(&mut 1), Err(1));
946
+ /// assert_eq!(Ok(&42), Ok(42));
947
+ /// ```
948
+ #[ unstable( feature = "result_copied" , reason = "newly added" , issue = "63168" ) ]
949
+ pub fn copied ( self ) -> Result < T , E > {
950
+ self . copied_ok ( ) . copied_err ( )
951
+ }
952
+ }
953
+
954
+ impl < T : Copy , E : Copy > Result < & mut T , & mut E > {
955
+ /// Maps a `Result<&mut T, &mut E>` to a `Result<T, E>` by copying
956
+ /// the contents of the result.
957
+ ///
958
+ /// # Examples
959
+ ///
960
+ /// ```
961
+ /// #![feature(result_copied)]
962
+ /// assert_eq!(Err(&mut 1), Err(1));
963
+ /// assert_eq!(Ok(&mut 42), Ok(42));
964
+ /// ```
965
+ #[ unstable( feature = "result_copied" , reason = "newly added" , issue = "63168" ) ]
966
+ pub fn copied ( self ) -> Result < T , E > {
967
+ self . copied_ok ( ) . copied_err ( )
968
+ }
969
+ }
970
+
903
971
impl < T : Clone , E > Result < & T , E > {
904
972
/// Maps a `Result<&T, E>` to a `Result<T, E>` by cloning the contents of the
905
973
/// `Ok` part.
@@ -915,7 +983,7 @@ impl<T: Clone, E> Result<&T, E> {
915
983
/// assert_eq!(cloned, Ok(12));
916
984
/// ```
917
985
#[ unstable( feature = "result_cloned" , reason = "newly added" , issue = "63168" ) ]
918
- pub fn cloned ( self ) -> Result < T , E > {
986
+ pub fn cloned_ok ( self ) -> Result < T , E > {
919
987
self . map ( |t| t. clone ( ) )
920
988
}
921
989
}
@@ -935,7 +1003,7 @@ impl<T: Clone, E> Result<&mut T, E> {
935
1003
/// assert_eq!(cloned, Ok(12));
936
1004
/// ```
937
1005
#[ unstable( feature = "result_cloned" , reason = "newly added" , issue = "63168" ) ]
938
- pub fn cloned ( self ) -> Result < T , E > {
1006
+ pub fn cloned_ok ( self ) -> Result < T , E > {
939
1007
self . map ( |t| t. clone ( ) )
940
1008
}
941
1009
}
@@ -980,6 +1048,74 @@ impl<T, E: Clone> Result<T, &mut E> {
980
1048
}
981
1049
}
982
1050
1051
+ impl < T : Clone , E : Clone > Result < & T , & E > {
1052
+ /// Maps a `Result<&T, &E>` to a `Result<T, E>` by cloning the contents of the
1053
+ /// result.
1054
+ ///
1055
+ /// # Examples
1056
+ ///
1057
+ /// ```
1058
+ /// #![feature(result_cloned)]
1059
+ /// assert_eq!(Err(&1).cloned(), Err(1));
1060
+ /// assert_eq!(Ok(&42).cloned(), Ok(42));
1061
+ /// ```
1062
+ #[ unstable( feature = "result_cloned" , reason = "newly added" , issue = "63168" ) ]
1063
+ pub fn cloned ( self ) -> Result < T , E > {
1064
+ self . cloned_ok ( ) . cloned_err ( )
1065
+ }
1066
+ }
1067
+
1068
+ impl < T : Clone , E : Clone > Result < & mut T , & E > {
1069
+ /// Maps a `Result<&mut T, &E>` to a `Result<T, E>` by cloning the
1070
+ /// contents of the result.
1071
+ ///
1072
+ /// # Examples
1073
+ ///
1074
+ /// ```
1075
+ /// #![feature(result_cloned)]
1076
+ /// assert_eq!(Err(&1).cloned(), Err(1));
1077
+ /// assert_eq!(Ok(&mut 42).cloned(), Ok(42));
1078
+ /// ```
1079
+ #[ unstable( feature = "result_cloned" , reason = "newly added" , issue = "63168" ) ]
1080
+ pub fn cloned ( self ) -> Result < T , E > {
1081
+ self . cloned_ok ( ) . cloned_err ( )
1082
+ }
1083
+ }
1084
+
1085
+ impl < T : Clone , E : Clone > Result < & T , & mut E > {
1086
+ /// Maps a `Result<&T, &mut E>` to a `Result<T, E>` by cloning the
1087
+ /// contents of the result.
1088
+ ///
1089
+ /// # Examples
1090
+ ///
1091
+ /// ```
1092
+ /// #![feature(result_cloned)]
1093
+ /// assert_eq!(Err(&mut 1).cloned(), Err(1));
1094
+ /// assert_eq!(Ok(&42).cloned(), Ok(42));
1095
+ /// ```
1096
+ #[ unstable( feature = "result_cloned" , reason = "newly added" , issue = "63168" ) ]
1097
+ pub fn cloned ( self ) -> Result < T , E > {
1098
+ self . cloned_ok ( ) . cloned_err ( )
1099
+ }
1100
+ }
1101
+
1102
+ impl < T : Clone , E : Clone > Result < & mut T , & mut E > {
1103
+ /// Maps a `Result<&mut T, &mut E>` to a `Result<T, E>` by cloning
1104
+ /// the contents of the result.
1105
+ ///
1106
+ /// # Examples
1107
+ ///
1108
+ /// ```
1109
+ /// #![feature(result_cloned)]
1110
+ /// assert_eq!(Err(&mut 1).cloned(), Err(1));
1111
+ /// assert_eq!(Ok(&mut 42).cloned(), Ok(42));
1112
+ /// ```
1113
+ #[ unstable( feature = "result_cloned" , reason = "newly added" , issue = "63168" ) ]
1114
+ pub fn cloned ( self ) -> Result < T , E > {
1115
+ self . cloned_ok ( ) . cloned_err ( )
1116
+ }
1117
+ }
1118
+
983
1119
impl < T , E : fmt:: Debug > Result < T , E > {
984
1120
/// Unwraps a result, yielding the content of an [`Ok`].
985
1121
///
0 commit comments