Skip to content

Commit 8e6ae19

Browse files
Add cloned example for Option
1 parent f50dbd5 commit 8e6ae19

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/libcore/option.rs

+10
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,16 @@ impl<T> Option<T> {
659659
impl<'a, T: Clone> Option<&'a T> {
660660
/// Maps an `Option<&T>` to an `Option<T>` by cloning the contents of the
661661
/// 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+
/// ```
662672
#[stable(feature = "rust1", since = "1.0.0")]
663673
pub fn cloned(self) -> Option<T> {
664674
self.map(|t| t.clone())

0 commit comments

Comments
 (0)