We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ba1d065 commit 51b29d6Copy full SHA for 51b29d6
src/libcore/option.rs
@@ -774,6 +774,25 @@ 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
+ /// let mut x = 12;
785
+ /// let opt_x = Some(&mut x);
786
+ /// assert_eq!(opt_x, Some(&mut 12));
787
+ /// let cloned = opt_x.cloned();
788
+ /// assert_eq!(cloned, Some(12));
789
790
+ #[unstable(feature = "option_ref_mut_cloned", issue = "0")]
791
+ pub fn cloned(self) -> Option<T> {
792
+ self.map(|t| t.clone())
793
+ }
794
+}
795
+
796
impl<T: Default> Option<T> {
797
/// Returns the contained value or a default
798
///
0 commit comments