We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents faf477a + 9618299 commit f2d7045Copy full SHA for f2d7045
src/libcore/option.rs
@@ -774,6 +774,26 @@ impl<'a, T: Clone> Option<&'a T> {
774
}
775
776
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
+
797
impl<T: Default> Option<T> {
798
/// Returns the contained value or a default
799
///
0 commit comments