@@ -820,6 +820,87 @@ impl<T, E> Result<T, E> {
820
820
}
821
821
}
822
822
823
+ impl < T : Copy , E > Result < & T , E > {
824
+ /// Maps a `Result<&T, E>` to a `Result<T, E>` by copying the contents of the
825
+ /// `Ok` part.
826
+ ///
827
+ /// # Examples
828
+ ///
829
+ /// ```
830
+ /// #![feature(result_copied)]
831
+ /// let val = 12;
832
+ /// let x: Result<&i32, i32> = Ok(&val);
833
+ /// assert_eq!(x, Ok(&12));
834
+ /// let copied = x.copied();
835
+ /// assert_eq!(copied, Ok(12));
836
+ /// ```
837
+ #[ unstable( feature = "result_copied" , reason = "newly added" , issue = "63168" ) ]
838
+ pub fn copied ( self ) -> Result < T , E > {
839
+ self . map ( |& t| t)
840
+ }
841
+ }
842
+
843
+ impl < T : Copy , E > Result < & mut T , E > {
844
+ /// Maps a `Result<&mut T, E>` to a `Result<T, E>` by copying the contents of the
845
+ /// `Ok` part.
846
+ ///
847
+ /// # Examples
848
+ ///
849
+ /// ```
850
+ /// #![feature(result_copied)]
851
+ /// let mut val = 12;
852
+ /// let x: Result<&mut i32, i32> = Ok(&mut val);
853
+ /// assert_eq!(x, Ok(&mut 12));
854
+ /// let copied = x.copied();
855
+ /// assert_eq!(copied, Ok(12));
856
+ /// ```
857
+ #[ unstable( feature = "result_copied" , reason = "newly added" , issue = "63168" ) ]
858
+ pub fn copied ( self ) -> Result < T , E > {
859
+ self . map ( |& mut t| t)
860
+ }
861
+ }
862
+
863
+ impl < T : Clone , E > Result < & T , E > {
864
+ /// Maps a `Result<&T, E>` to a `Result<T, E>` by cloning the contents of the
865
+ /// `Ok` part.
866
+ ///
867
+ /// # Examples
868
+ ///
869
+ /// ```
870
+ /// #![feature(result_cloned)]
871
+ /// let val = 12;
872
+ /// let x: Result<&i32, i32> = Ok(&val);
873
+ /// assert_eq!(x, Ok(&12));
874
+ /// let cloned = x.cloned();
875
+ /// assert_eq!(cloned, Ok(12));
876
+ /// ```
877
+ #[ unstable( feature = "result_cloned" , reason = "newly added" , issue = "63168" ) ]
878
+ pub fn cloned ( self ) -> Result < T , E > {
879
+ self . map ( |t| t. clone ( ) )
880
+ }
881
+ }
882
+
883
+ impl < T : Clone , E > Result < & mut T , E > {
884
+ /// Maps a `Result<&mut T, E>` to a `Result<T, E>` by cloning the contents of the
885
+ /// `Ok` part.
886
+ ///
887
+ /// # Examples
888
+ ///
889
+ /// ```
890
+ /// #![feature(result_cloned)]
891
+ /// let mut val = 12;
892
+ /// let x: Result<&mut i32, i32> = Ok(&mut val);
893
+ /// assert_eq!(x, Ok(&mut 12));
894
+ /// let cloned = x.cloned();
895
+ /// assert_eq!(cloned, Ok(12));
896
+ /// ```
897
+ #[ unstable( feature = "result_cloned" , reason = "newly added" , issue = "63168" ) ]
898
+ pub fn cloned ( self ) -> Result < T , E > {
899
+ self . map ( |t| t. clone ( ) )
900
+ }
901
+ }
902
+
903
+
823
904
impl < T , E : fmt:: Debug > Result < T , E > {
824
905
/// Unwraps a result, yielding the content of an [`Ok`].
825
906
///
0 commit comments