Skip to content

Commit

Permalink
Rollup merge of rust-lang#38090 - GuillaumeGomez:option_doc, r=frewsxcv
Browse files Browse the repository at this point in the history
Add cloned example for Option

r? @frewsxcv
  • Loading branch information
frewsxcv authored Dec 3, 2016
2 parents d0e57b1 + 8e6ae19 commit 6c327ad
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,16 @@ impl<T> Option<T> {
impl<'a, T: Clone> Option<&'a T> {
/// Maps an `Option<&T>` to an `Option<T>` by cloning the contents of the
/// option.
///
/// # Examples
///
/// ```
/// let x = 12;
/// let opt_x = Some(&x);
/// assert_eq!(opt_x, Some(&12));
/// let cloned = opt_x.cloned();
/// assert_eq!(cloned, Some(12));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn cloned(self) -> Option<T> {
self.map(|t| t.clone())
Expand Down

0 comments on commit 6c327ad

Please sign in to comment.