Skip to content

Commit

Permalink
Implement Clone::clone_from for Option.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ou-se committed Jun 1, 2019
1 parent c28084a commit cb12460
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ use crate::pin::Pin;
// which basically means it must be `Option`.

/// The `Option` type. See [the module level documentation](index.html) for more.
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
#[derive(Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
#[stable(feature = "rust1", since = "1.0.0")]
pub enum Option<T> {
/// No value
Expand Down Expand Up @@ -1040,6 +1040,25 @@ fn expect_failed(msg: &str) -> ! {
// Trait implementations
/////////////////////////////////////////////////////////////////////////////

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Clone> Clone for Option<T> {
#[inline]
fn clone(&self) -> Self {
match self {
Some(x) => Some(x.clone()),
None => None,
}
}

#[inline]
fn clone_from(&mut self, source: &Self) {
match (self, source) {
(Some(to), Some(from)) => to.clone_from(from),
(to, from) => *to = from.clone(),
}
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for Option<T> {
/// Returns [`None`][Option::None].
Expand Down

0 comments on commit cb12460

Please sign in to comment.