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 464faa1 + 8e6ae19 commit 0c28d5dCopy full SHA for 0c28d5d
src/libcore/option.rs
@@ -659,6 +659,16 @@ impl<T> Option<T> {
659
impl<'a, T: Clone> Option<&'a T> {
660
/// Maps an `Option<&T>` to an `Option<T>` by cloning the contents of the
661
/// option.
662
+ ///
663
+ /// # Examples
664
665
+ /// ```
666
+ /// let x = 12;
667
+ /// let opt_x = Some(&x);
668
+ /// assert_eq!(opt_x, Some(&12));
669
+ /// let cloned = opt_x.cloned();
670
+ /// assert_eq!(cloned, Some(12));
671
672
#[stable(feature = "rust1", since = "1.0.0")]
673
pub fn cloned(self) -> Option<T> {
674
self.map(|t| t.clone())
0 commit comments