about summary refs log tree commit diff
path: root/src/libcollections
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-02-05 06:51:05 +0000
committerbors <bors@rust-lang.org>2016-02-05 06:51:05 +0000
commit2ad6dc2556c19f49280b561fc1f5246ff9f9d6ed (patch)
tree784edc64890c58f7874972f0af2dcca4818b44ae /src/libcollections
parentdcf8ef2723d106c3467a2ee17746aa5768c3cdc6 (diff)
parentb27b8f63bc51d9aba2a1fe88cf428243d4fedfa8 (diff)
Auto merge of #31386 - tbu-:pr_cow_from_vec, r=alexcrichton
Fixes #31354.
Diffstat (limited to 'src/libcollections')
-rw-r--r--src/libcollections/vec.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs
index a49b7304643..805d9a9807a 100644
--- a/src/libcollections/vec.rs
+++ b/src/libcollections/vec.rs
@@ -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]> {