From 703d7b519e69daf03e34edcd1af2957e393414b5 Mon Sep 17 00:00:00 2001 From: Aaronepower Date: Thu, 16 Jun 2016 14:44:56 +0100 Subject: [PATCH] Added Default trait for Cow --- src/libcollections/borrow.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libcollections/borrow.rs b/src/libcollections/borrow.rs index 6ca0db68a88ce..37dbeb4eae17d 100644 --- a/src/libcollections/borrow.rs +++ b/src/libcollections/borrow.rs @@ -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; @@ -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, + ::Owned: Default +{ + fn default() -> Cow<'a, B> { + Owned(::Owned::default()) + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<'a, B: ?Sized> Hash for Cow<'a, B> where B: Hash + ToOwned { #[inline]