Implement Clone::clone_from for Option.
This commit is contained in:
parent
c28084ac16
commit
cb12460467
1 changed files with 20 additions and 1 deletions
|
@ -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
|
||||
|
@ -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].
|
||||
|
|
Loading…
Reference in a new issue