File tree 1 file changed +42
-0
lines changed
1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -884,6 +884,48 @@ impl<T> Option<T> {
884
884
}
885
885
}
886
886
887
+ impl < ' a , T : Copy > Option < & ' a T > {
888
+ /// Maps an `Option<&T>` to an `Option<T>` by copying the contents of the
889
+ /// option.
890
+ ///
891
+ /// # Examples
892
+ ///
893
+ /// ```
894
+ /// #![feature(copied)]
895
+ ///
896
+ /// let x = 12;
897
+ /// let opt_x = Some(&x);
898
+ /// assert_eq!(opt_x, Some(&12));
899
+ /// let copied = opt_x.copied();
900
+ /// assert_eq!(copied, Some(12));
901
+ /// ```
902
+ #[ unstable( feature = "copied" , issue = "0" ) ]
903
+ pub fn copied ( self ) -> Option < T > {
904
+ self . map ( |& t| t)
905
+ }
906
+ }
907
+
908
+ impl < ' a , T : Copy > Option < & ' a mut T > {
909
+ /// Maps an `Option<&mut T>` to an `Option<T>` by copying the contents of the
910
+ /// option.
911
+ ///
912
+ /// # Examples
913
+ ///
914
+ /// ```
915
+ /// #![feature(copied)]
916
+ ///
917
+ /// let mut x = 12;
918
+ /// let opt_x = Some(&mut x);
919
+ /// assert_eq!(opt_x, Some(&mut 12));
920
+ /// let copied = opt_x.copied();
921
+ /// assert_eq!(copied, Some(12));
922
+ /// ```
923
+ #[ unstable( feature = "copied" , issue = "0" ) ]
924
+ pub fn copied ( self ) -> Option < T > {
925
+ self . map ( |& mut t| t)
926
+ }
927
+ }
928
+
887
929
impl < ' a , T : Clone > Option < & ' a T > {
888
930
/// Maps an `Option<&T>` to an `Option<T>` by cloning the contents of the
889
931
/// option.
You can’t perform that action at this time.
0 commit comments