Skip to content

Commit f30f569

Browse files
committed
Add Cow::from for Vec and slices
Fixes #31354.
1 parent 59b7c90 commit f30f569

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/libcollections/vec.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,20 @@ impl<'a> From<&'a str> for Vec<u8> {
15051505
// Clone-on-write
15061506
////////////////////////////////////////////////////////////////////////////////
15071507

1508+
#[stable(feature = "cow_from_vec", since = "1.7.0")]
1509+
impl<'a, T: Clone> From<&'a [T]> for Cow<'a, [T]> {
1510+
fn from(s: &'a [T]) -> Cow<'a, [T]> {
1511+
Cow::Borrowed(s)
1512+
}
1513+
}
1514+
1515+
#[stable(feature = "cow_from_vec", since = "1.7.0")]
1516+
impl<'a, T: Clone> From<Vec<T>> for Cow<'a, [T]> {
1517+
fn from(v: Vec<T>) -> Cow<'a, [T]> {
1518+
Cow::Owned(v)
1519+
}
1520+
}
1521+
15081522
#[stable(feature = "rust1", since = "1.0.0")]
15091523
impl<'a, T> FromIterator<T> for Cow<'a, [T]> where T: Clone {
15101524
fn from_iter<I: IntoIterator<Item = T>>(it: I) -> Cow<'a, [T]> {

0 commit comments

Comments
 (0)