Skip to content

Commit

Permalink
Add Cow::from for Vec and slices
Browse files Browse the repository at this point in the history
Fixes #31354.
  • Loading branch information
tbu- committed Feb 3, 2016
1 parent 59b7c90 commit f30f569
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/libcollections/vec.rs
Expand Up @@ -1505,6 +1505,20 @@ impl<'a> From<&'a str> for Vec<u8> {
// Clone-on-write
////////////////////////////////////////////////////////////////////////////////

#[stable(feature = "cow_from_vec", since = "1.7.0")]
impl<'a, T: Clone> From<&'a [T]> for Cow<'a, [T]> {
fn from(s: &'a [T]) -> Cow<'a, [T]> {
Cow::Borrowed(s)
}
}

#[stable(feature = "cow_from_vec", since = "1.7.0")]
impl<'a, T: Clone> From<Vec<T>> for Cow<'a, [T]> {
fn from(v: Vec<T>) -> Cow<'a, [T]> {
Cow::Owned(v)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> FromIterator<T> for Cow<'a, [T]> where T: Clone {
fn from_iter<I: IntoIterator<Item = T>>(it: I) -> Cow<'a, [T]> {
Expand Down

0 comments on commit f30f569

Please sign in to comment.