about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-07-30 10:25:23 +0000
committerbors <bors@rust-lang.org>2015-07-30 10:25:23 +0000
commit87055a68c3194db212456f99ece080728a5fc2f8 (patch)
tree9908d4b080e8dac63662d25e5f498ae837a41456 /src/liballoc
parentf97a82fd435b2f6e62d9f76a15ea4aeb6933b85c (diff)
parent3e954a8cb2fd094d79713059d83d37b2daa7b396 (diff)
downloadrust-87055a68c3194db212456f99ece080728a5fc2f8.tar.gz
rust-87055a68c3194db212456f99ece080728a5fc2f8.zip
Auto merge of #27371 - Gankro:str-clone, r=alexcrichton
This is a minor [breaking-change], as it changes what
`boxed_str.to_owned()` does (previously it would deref to `&str` and
call `to_owned` on that to get a `String`). However `Box<str>` is such an
exceptionally rare type that this is not expected to be a serious
concern. Also a `Box<str>` can be freely converted to a `String` to
obtain the previous result anyway.
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/boxed.rs13
-rw-r--r--src/liballoc/lib.rs1
2 files changed, 14 insertions, 0 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs
index 0c2e7eb6bb3..9420a88bade 100644
--- a/src/liballoc/boxed.rs
+++ b/src/liballoc/boxed.rs
@@ -325,6 +325,19 @@ impl<T: Clone> Clone for Box<T> {
     }
 }
 
+
+#[stable(feature = "box_slice_clone", since = "1.3.0")]
+impl Clone for Box<str> {
+    fn clone(&self) -> Self {
+        let len = self.len();
+        let buf = RawVec::with_capacity(len);
+        unsafe {
+            ptr::copy_nonoverlapping(self.as_ptr(), buf.ptr(), len);
+            mem::transmute(buf.into_box()) // bytes to str ~magic
+        }
+    }
+}
+
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: ?Sized + PartialEq> PartialEq for Box<T> {
     #[inline]
diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs
index 03cf4fc9fc1..0e9b01e5c23 100644
--- a/src/liballoc/lib.rs
+++ b/src/liballoc/lib.rs
@@ -92,6 +92,7 @@
 #![feature(unsafe_no_drop_flag, filling_drop)]
 #![feature(unsize)]
 #![feature(core_slice_ext)]
+#![feature(core_str_ext)]
 
 #![cfg_attr(test, feature(test, alloc, rustc_private, box_raw))]
 #![cfg_attr(all(not(feature = "external_funcs"), not(feature = "external_crate")),