Skip to content

Commit

Permalink
Rollup merge of rust-lang#34305 - Aaronepower:master, r=alexcrichton
Browse files Browse the repository at this point in the history
Added Default trait for Cow.

Adds a default implementation for Cow. Which is the Owned's default.
  • Loading branch information
jseyfried committed Jun 29, 2016
2 parents 2fda7d4 + 703d7b5 commit a77a179
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/libcollections/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use core::clone::Clone;
use core::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
use core::convert::AsRef;
use core::default::Default;
use core::hash::{Hash, Hasher};
use core::marker::Sized;
use core::ops::Deref;
Expand Down Expand Up @@ -248,6 +249,16 @@ impl<'a, B: ?Sized> fmt::Display for Cow<'a, B>
}
}

#[stable(feature = "default", since = "1.11.0")]
impl<'a, B: ?Sized> Default for Cow<'a, B>
where B: ToOwned,
<B as ToOwned>::Owned: Default
{
fn default() -> Cow<'a, B> {
Owned(<B as ToOwned>::Owned::default())
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, B: ?Sized> Hash for Cow<'a, B> where B: Hash + ToOwned {
#[inline]
Expand Down

0 comments on commit a77a179

Please sign in to comment.