File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -774,6 +774,26 @@ impl<'a, T: Clone> Option<&'a T> {
774774 }
775775}
776776
777+ impl < ' a , T : Clone > Option < & ' a mut T > {
778+ /// Maps an `Option<&mut T>` to an `Option<T>` by cloning the contents of the
779+ /// option.
780+ ///
781+ /// # Examples
782+ ///
783+ /// ```
784+ /// #![feature(option_ref_mut_cloned)]
785+ /// let mut x = 12;
786+ /// let opt_x = Some(&mut x);
787+ /// assert_eq!(opt_x, Some(&mut 12));
788+ /// let cloned = opt_x.cloned();
789+ /// assert_eq!(cloned, Some(12));
790+ /// ```
791+ #[ unstable( feature = "option_ref_mut_cloned" , issue = "43738" ) ]
792+ pub fn cloned ( self ) -> Option < T > {
793+ self . map ( |t| t. clone ( ) )
794+ }
795+ }
796+
777797impl < T : Default > Option < T > {
778798 /// Returns the contained value or a default
779799 ///
You can’t perform that action at this time.
0 commit comments