Skip to content

Commit 703d7b5

Browse files
author
Aaronepower
committed
Added Default trait for Cow
1 parent a479a6a commit 703d7b5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/libcollections/borrow.rs

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use core::clone::Clone;
1616
use core::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
1717
use core::convert::AsRef;
18+
use core::default::Default;
1819
use core::hash::{Hash, Hasher};
1920
use core::marker::Sized;
2021
use core::ops::Deref;
@@ -248,6 +249,16 @@ impl<'a, B: ?Sized> fmt::Display for Cow<'a, B>
248249
}
249250
}
250251

252+
#[stable(feature = "default", since = "1.11.0")]
253+
impl<'a, B: ?Sized> Default for Cow<'a, B>
254+
where B: ToOwned,
255+
<B as ToOwned>::Owned: Default
256+
{
257+
fn default() -> Cow<'a, B> {
258+
Owned(<B as ToOwned>::Owned::default())
259+
}
260+
}
261+
251262
#[stable(feature = "rust1", since = "1.0.0")]
252263
impl<'a, B: ?Sized> Hash for Cow<'a, B> where B: Hash + ToOwned {
253264
#[inline]

0 commit comments

Comments
 (0)