diff options
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/boxed.rs | 13 | ||||
| -rw-r--r-- | src/liballoc/lib.rs | 1 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index db338eaaf00..58c10b6ea59 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -321,6 +321,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))] #